본문 바로가기

JavaScript14

JavaScript operator if for loop // 1. String concatenation console.log('my'+'cat'); //출력결과 my cat console.log('1'+ 2); //출력결과 12 console.log(`string literals : 1 + 2 = ${1 + 2}`); //출력결과 1 + 2 = 3 //2. Numberic operators console.log(2 ** 3); //n승 //3.Increment and decrement operators let counter = 2; const preIncrement = ++counter; console.log(`preIncrement: ${preIncrement}, counter:${counter}`); //출력결과 preIncrement: 3 counter.. 2022. 1. 26.
데이터타입, data types, let vs var, hoisting 'use strict'; let globaName = 'global name'; //block scope밖에 선언한 변수는 block scope안이든 block scope밖이든 어디든지 출력가능 /*glpbal var은 어플리케이션 실행후 항상 메모리에 있기 때문에 꼭필요한 경우에만 최소한으로 쓰는 것이 좋음 ex) for class if 등등 */ { //block scope 안에 있는 것은 안에서만 출력 가능 let name = 'son'; //son이라는 것을 담는 변수 name console.log(name); //출력 name = 'hello'; //다시 name에 hello라는 변수를 할당 console.log(name); //name 출력 hello console.log(globaName);.. 2022. 1. 21.
기타 false로 간주되는 데이터 형 if(!''){ //자바스크립트에서 ''은 false로 간주되기 때문에 !''하면 조건문이 실행됨 alert('빈 문자열') } if(!undefined){ //자바스크립트에서 undefined은 false로 간주되기 때문에 !undefined 하면 조건문이 실행됨 alert('undefined'); } var a; if(!a){ //변수 a를 선언했으나 a안에 값이 들어있지 않기 때문에 undefined이므로 !a 하면 조건문이 실행됨 alert('값이 할당되지 않은 변수'); } if(!null){ //자바스크립트에서 null값은 false로 간주되기 때문에 !null하면 조건문이 실행됨 alert('null'); } if(!NaN){ //자바스크립트에서 NaN값은 false로 간주되기 때문에 !Na.. 2022. 1. 17.
자바스크립트 숫자와 문자 Math.pow(3.2); //제곱근 9 Math.round(10.6); // 반올림 11 Math.ceil(10.2); //올림 11 Math.floor(10.2); //내림 10 Math.sqrt(9); //제곱근 3 Math.random(); //0~1사이의 난수 100*Math.random(); //난수 0~100 사이 alert('egoing\'s coding everybody'); //출력형태 egoing's coding everybody 즉 '를 출력하기 위한 \(역슬래쉬) 2022. 1. 12.