본문 바로가기

Javascript

(5)
[JavaScript] 객체 objet 함수, 클래스 (틀) => 객체, 개체, object function 틀( ) { } => new 틀( ) : 생성자 함수로 객체 만들기 function A() {} const a =new A(); console.log(a, typeOf a); // A {} 'object' 출력됨 console.log(A()); // undefined 출력됨 //생성하면서 데이터 넣기 function B(name, age) { console.log(name, age); // Mark 37 출력됨 } const b = new B(); const c = new B('Mark', 37); console.log(B()); // undefined 출력됨 객체에 속성 추가하기 property //값을 속성으로 넣기 function..
[JavaScript] 함수 function //function //이름이 hello인 함수 function hello() { console.log('hello'); } console.log(hello, typeOf hello); // 출력 : [function: hello] 'function' // 함수의 매개변수 //함수를 호출 할 값을 지정 function hello2(name) { console.log('hello2', name) } // 함수의 리턴 // 함수를 실행하면 얻어지는 값 function hello3(name) { return `hello3 ${name}`; } console.log(hello3('Hyewon')); const hello = function( ) { } 함수를 만들 때 사용하는 키워드 const ..
[JavaScript] 반복문 for 문 for(초기화; 반복조건; 반복이 된 후 실행되는 코드) { 반복이 되는 코드 블럭 } for(a; b; c) { d } e 실행 순서 : a → d → c → b → d → c → b → e for(; ;) { d } → 무한 루프 → if문을 넣어 빠져나올 수 있음 while (조건) { 조건이 거짓이 될 때까지 반복 실행 } while (true) { console.log('안녕하세요'); if (Math.random() * 100 > 90) { break; } } do { 조건이 거짓이 될 때까지 반복 실행 } while (조건) ; 한 번은 실행됨 do { console.log('안녕하세요'); while (Math.random() * 100 > 90); } for of (iterab..
[JavaScript] 조건문 표현식이 거짓으로 평가될 때 (Falsy) false 0 null undefined NaN 표현식이 참으로 평가될 때 (Truethy) true 24 'Hyewon' { } [ ] if (false) console.log(false); if (0) console.log(false); if ('') console.log(''); if (null) console.log(null); if (undefined) console.log(undefined); if (NaN) console.log(NaN); → 출력되지 않음 if(true) console.log(true); if(24) console.log(24); if(-24) console.log(-24); if('Hyewon') console.log('Hyewo..
[JavaScript] 시작하면서 식별자 대소문자 구분함 '예약어', '공백문자' 사용불가 var myName = "강혜원"; var myname = "kanghyewon; myName != myname (식별자) 변수와 상수 (variable and constant) const 상수를 _지칭하는_이름; : 상수를 선언하는 방법 let 변수를 _지칭하는_이름; : 변수를 선언하는 방법 const sum = 5 + 10; let result = false; if(sum% 3 == 0) { console.log('안녕3'); result = true; } if(sum % 5 == 0) { console.log('안녕5'); result = true; } console.log(result); 변수의 유효범위 (scope of variable)..