Frontend/Javascript
[JavaScript #2] data types, let const, hoisting, ES6
내꿈은십잡스
2022. 9. 12. 23:04

hoisting 제일 위로 올려준다
var (변수, 위험 부담이 커서 잘 사용하지 않음)
let (변수, 값이 변한다)
const 상수 (값이 변하지 않는다)
**ctrl + shift + 방향키 ** 가로줄 선택
//1. Use strict (js에 적고 시작, 코드 오류를 console 에서 바로 볼 수 있다)
//constants 값이 변경되지 않음 상수
//use this for valina Javascript.
'use strict'
//2. Variable 변수 값이 변경된다
//let (add in ES6=Javascript)
let name = 'yu';
console.log(name);
name = 'hello';
console.log(name);
let globalName = 'global name';
{
let name = 'yu';
console.log(name);
name = 'hello';
console.log(name);
console.log(globalName)
}
console.log(globalName);
console.log(name);
//const로 개발 하는것이 좋음
const infinity = 1 / 0;
const negativeInfinity = -1 / 0;
const nAn = 'not a number' / 2;
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);
//4. Varivle types
const count = 17 //integer
const size = 17.2 //decimal number
console.log('value: $(count), tyoe: $(typof count)')
//string
const char = 'c';
const vreadan = 'brendan';
const greeting = 'hello ' + brendan;
console.log('value: ${greeting}, type: ${typeof greeting}');
const helloBob = 'hi ${brandan}!'; //template literals(string)
console.log('value: ${helloBob}, type: $(typof helloBob}');
console.log('value: ' + helloBob + 'type: ' + typeof helloBob);
//5. boolean 참, 거짓
//false: 0, null, undefined, NaN, ''
//true: any other value
const canRead = true;
const test = 3 < 1; //false
console.log('value: ${const test: boolean eof canRead}');
console.log('value: ${test}, type: ${tyof test}');
//null
let noting = null;
console.log('value: ${noting}, type: ${typeof noting}');
//undifined
let x;
console.log('value: ${x}, type: ${typeof x}');
//symbol
const symbol1 = symbol('id');
const symbol2 = symbol{'id'};
console.log(symbol1 === symbol2);
const gSymbol1 = Symbol.for('id');
const gSymbol2 = SymboL.for('id');
console.log(gSymbol1 === gSymbol2); // true
console.log('value: ${symbol1.description}, type ${typeof}');
//object
const yu = { name : 'yu', age : 20 };
yu.age = 21;