웹 개발/🌐 JavaScript

웹 개발/🌐 JavaScript

es6+ | 자바스크립트의 한계와 Null

만약 객체에 없는 값을 찍으면 undefined가 뜬다 const ob = { name: 'jae', age: 25, uni: 'harvard', major: 'sw' } console.log(ob.country); ?연산자 지금은 콘솔환경이라 undefined 나 나타나지만 나중에 서버환경에서는 errorr가 발생할수있다 만약 어떤 객체에 존재하지 않는 속성에 접근하려고 하면 error가 나타날수 있다 그래서 있는지 없는지 확실치 않을때 ? 를 붙이면 error 대신 undefined를 return 해준다 console.log(ob?.country?.hi.hello.how.are.you); ?? 연산자 console.log(ob.country ?? "seoul"); ob.country 가 null 이면..

웹 개발/🌐 JavaScript

es6+ | 객체

function prt4() { console.log("hello world4"); } const ob = { name: "yongsoo", age: 25, func1: function prt() { console.log("hello world") }, func2: () => { console.log("hello world2"); }, func3() { console.log("hello world3"); }, //아래처럼 변수에다가 넣을 수도 있고 func4: prt4(), //구조분해를 이용하면 prt4: prt4(), //얘를 아래처럼 생략가능 prt4 }; ob.prt4 리터럴 객체 const test = "Test word"; const liter = `test word but ${test} $..

웹 개발/🌐 JavaScript

es6+ | 비구조화 할당

| 비구조화 할당 1.객체의 벨류파라미터 생략 화살표 함수에서 객체를 return할때 // 객체의 키값과 벨류의 파라미터명이 같으면 벨류파라미터 생략가능 const register1 = (ID,PW) => ({ID:ID ,PW:PW}) const register2 = (ID,PW) => ({ID,PW}) console.log(register1("jae",0001)) console.log(register2("jae",0001)) 객체선언할때 //객체 const man = {name: "jae", age:24, sex:"male"}; 키의 값을 뽑아내려면 아래와같이 man.name 이런식으로 적어야한다 console.log(man.name) console.log(man.age) console.log(man...

웹 개발/🌐 JavaScript

es6+ | 화살표 함수

function add(a,b){ return a + b; } // arrow func 기본형 const add2 = (a, b) => { return a + b; }; // return 1줄일땐 return생략가능 const add3 = (a, b) => a + b; // param 1개일땐 ()소괄호 생략가능 const add4 = a => a + 4 // 객체 반환 const add5 = (a) => { return {hello : "world" }; }; //return 이 한줄일때는 return 생략가능 //하지만 객체를 반환할때는 소괄호를 적어줘야함 const add6 = (a) => ({hello : "world"});

웹 개발/🌐 JavaScript

쿠키를 이용하여 아이디저장기능 구현

1. 로그인 아이디 저장하기 2. 아이디 저장 $(document).ready(function(){ var key = getCookie("key"); $("#userId").val(key); if($("#userId").val() != ""){ $("#idSaveCheck").attr("checked", true); } $("#idSaveCheck").change(function(){ if($("#idSaveCheck").is(":checked")){ setCookie("key", $("#userId").val(), 7); //7일간 보관 }else{ deleteCookie("key"); } }); $("#userId").keyup(function(){ if($("#idSaveCheck").is(":ch..

웹 개발/🌐 JavaScript

fetch함수

🤷‍♂️ fetch란? fetch 는 client가 서버에 요청을 보낼 때 사용하는 함수이다. 예를 들어, fetch('javascript') 라는 표현은 "웹브라우저야, javascript 라는 파일을 서버에 응답해줘" 라는 뜻이다. 동기(synchronous) : A가 끝나야 그 다음 B를 실행하는 처리방식 비동기(Asynchronous) : A가 끝나지 않아도 B를 실행하는 처리방식 기본적으로 fetch() 함수는 비동기 처리에 해당한다. fetch를 동기적 처리로 만들기 위해 .then()을 사용한다. 🧑‍💻 예제 코드 function callBackMe() { console.log("response end") } fetch('html').then(callBackMe); console.log(1)..

이재원
'웹 개발/🌐 JavaScript' 카테고리의 글 목록 (3 Page)