: 변경 될수 있는 값
🌱 let (added in ES6) : Mutable
let name = "nana";
console.log(name);
name = 'hello';
console.log(name);
: 코드를 블록 안에 작성하게 되면 블록 밖에서는 더 이상 블록 안에 있는 애들을 볼 수가 없다.
let globalName = 'global name';
{
let name = "nana";
console.log(name);
name = 'hello';
console.log(name);
}
: 한번 할당하면 값이 절대 바뀌지 않는 것을 말함.(const)
favor immutable data type always for a few reasons;
- primitive, single item: number, string, boolean, null, undefied, symbol
- object, box container
- function, first-class function
int main() {
short a = 12. // 2 bytes
int b = 12; // 4 bytes
long c = 1234; // 8 bytes
float d = 1.2f; // 4 bytes
double e = 8.2; // 16 bytes
return 0;
}
const count = 19; //integer
const size = 19.2; //decimal number
console.log(`value: ${count}, type: ${typeof count}`);
console.log(`value: ${size}, type: ${typeof size}`);
//number - speicla numeric values: infinity, -infinity, NaN
const infinity = 1 / 0; //양의 무한대를 나나태내는 숫자값
const negativeInfinity = -1 / 0; //음의 무한대
const nAn = 'not a number' / 2; //숫자가 아닌 string을 숫자로 나누면
console.log(infinity);
console.log(negativeInfinity);
console.log(nAn);
//bigInt (fairly new, don't use it yet)
_**const bigInt = 12345678901234567890n; **_ //over (-2**53 ~2*53)
console.log(`value: ${bigInt}, type: ${typeof bigInt}`);
Number.Max_SAFE_INTEGER;
🌿 boolean
🌿 null & undefined
//symbol
const symbol1 = symbol('id');
const symbol2 = symbol('id');
console.log(symbol1 === symbol2);
// 출력 : false
// 같은 값을 할당해줘도 고유한 식별이기 때문에 비교연산을 해도 다르다고 나옴.
// 동일한 symbol도 만들 수 있다
symbol 을 그냥 출력하면 에러가 난다.
출력할 때는 .description 으로 문자열로 만들어준 뒤 출력해야한다.
console.log(`value: ${symbol.description}`)
: 자바나 c 언어는 변수를 선언할 때 어떤 타입인지 결정해서 타입을 같이 선언했던 반면에 자바스크립트는 선언할 때 어떤 타입인지 선언하지 않고 run type 프로그램이 동작할 때 할당된 값에 따라서 타입이 변경 될 수 있다는 것을 말함.
: + 기호를 이용해서 문자열과 문자열을 합해서 새로운 문자열을 만든다.
-> 줄바꿈 : \n, \tab
-> if 좀더 간단하게 쓸 수 있는 ? 쓰면 => true 면 왼쪽(true) 실행하고, :(아니면) ' no' 실행해줘.
-> 값을 할당하거나 출력할 때 많이 쓰임.
-> 블록을 먼저 실행 후 조건이 맞는지 안 맞는지 검사함.
-fundametal building block in the program
-subprogram can be used multiple times
-performs a task or calculates a value
function printHello () {
console.log('Hello')
}
printHello(); // 쓸모가 별로 없다.
function log(message) {
console.log(message);
}
log('Hello');
log(1234);
-> 배열 형태로 전달 (...args)
-> 간단하게 출력하는 방법
다시 시작된 자바스크립트 강의...
배열까지만 들었던 강의 이제서야 다시 처음부터 듣게 되었다. 아직 갈길이 멀지만 내가 맞는 강사를 찾기도 어려웠다. dreamcoding 앨리님 그나마 집중도도 높여주고 머릿속에 제일 많이 남는것같다. 물론 나의 사고력을 높이기 위해 시간을 갖아야 하지만 오늘은 step by step 으로 훑는다고 생각하고 차근차근 살을 붙여가보자.