let은 ES6에서 사용되는 변수이다.
const는 ES6에서 사용되는 상수이다. //보안
{
이곳에 작성한 코드에서는 안에서 블럭 밖은 볼 수 있다.
밖에서는 이 곳을 볼 수 없다.
}
Var은 사용하지 않는다.
// 순서가 없다, 위에서 보았듯이 블럭을 이용하여 변수를 선언하면 위의 기능을 무시한다.
호이스팅이란, 어디에 선언했느냐에 상관없이 항상 제일 위로 선언을 끌어올리는 것 이다.
//variable types
number, string, boolean, null, undefiedn, symbol, object, box container, function, first-class function
DATA TYPE IS NUMBER
const count = 17; //integer
const size = 17.1; //decimal number
console.log (``value: ${count}, type: ${typeof count)``);
console.log (``value: ${size}, type: ${typeof size)``);
proceed, result is value : 17, type: number value : 17.1, type: numbr
CHECKING ABOUT "IS THIS NUMBER?"
const infinity = 1/0;
const negativeInfinity = -1/0;
const nAn = 'not a number' / 2;
console.log (infinity);
console.log (negativeInfinity);
console.log (nAn);
proceed, result is
Infinity //if you make program culculate 0 divide to number, this program will be show this..
-Infinity // about "-number".
NaN //if value is not number, program will show this..
Recently, javascripts add big int type..
In general, javascript provides the size of the data type of number as $-2^{53}$~$2^{53}$.
However, larger numeric datatypes are now available.
You can use this by appending 'n' after the number.
STRING
const char ='c';
const bredan = 'brendan';
const greeting = 'hello' + bredan;
console.log (`value: ${greeting}, type: ${typeof greeting}`);
const helloBob = `hi ${bredan}!`;
console.log (`value: ${helloBob}, type: ${typeof helloBob}`);
proceed, result is
value: hello brendan, type: string
value: hi bredan!, type: string
BOOLEAN
const canRead = true;
const test = 3<1; //false
let and undefined is diffrent
let nothing = null;
console.log (`value: ${nothing}, type: ${typeof nothing}`);
//console
//null, object
let x;
console.log (`value: ${x}, type: ${typeof x}`);
//console
//undefined undefined
SYMBOL //create unique identifiers for objects
const symbol1 = Symbol('id');
const symbol2 = Symbol('id');
console.log(symbol1 === symbol2); //false
const gSymbol1 = Symbol.for('id');
const gSymbol1 = Symbol.for('id');
console.log (gSymbol1 === gSymbol2); //true
console.log (`value: ${symbol1.description}, type: ${typeof symbol1.description}`);
Dynamic typing : dynamically typed language
'JavaScript' 카테고리의 다른 글
ES6 문법을 다루기 (0) | 2022.05.23 |
---|---|
자바스크립트 동기적, 비동기적 실행, 콜백함수 (0) | 2021.07.15 |
console.log("자바스크립트 출력 메소드"); (0) | 2021.07.01 |