본문 바로가기

TIL/JAVASCRTIPT

(4)
Section2-33~37 Function "A function is a piece of code that we can reuse over and over again in our code" Function declarations vs. expressions // function declarations function calcAge1(birthYear) { return 2021-birthYear; } const age1 = calcAge1(2000); // function expressions const calcAge2 = function(birthYear){ return 2021-birthYear; } const age2 = calcAge2(2000); function expressions부분에서 익명함수 부분은 statement가 아니라 (당연..
Section2-20 Type Conversion and Coercion "type conversion is when we manually convert from one type to another. On the other hand type coercion is when Javscript automatically converts type behind the scenes for us" type conversion 직접 타입을 바꿔주는 것을 뜻한다. const inputYear = '2020'; console.log(inputYear + 10); // 202010 console.log(Number(inputYear) + 10); // 2030 console.log(Number('hoho')); // NaN console.log(typeof NaN); // number 위에서 Nu..
Section2-13 let, const, var let 값이 변경될 가능성이 있는 경우, let을 통해 변수 선언을 한다. 예를 들어 'age'변수의 경우 고정값이 아닌 변동될 가능성이 있으므로 이 경우에는 let으로 선언하는 것이 타당하다. "we use the let keyword to declare variables that can change later so basically during the execution of our program" 변경 가능하므로 아래와 같이 값을 재할당할 수 있다. let age = 30; ... age = 31; 이를 reassigning 혹은 mutate라고 한다. 즉 mutate할 필요가 있는 변수는 let으로 선언한다. "when we need to mutate a variable, that's the per..
Section2-12 Data Type data type primitive data type in js 1. Number: Floating point numbers → Used for decimals and integers 소수, 정수 모두 사용된다. 즉 소수, 정수 모두 number 데이터 타입이다. 2. String: Sequence of characters → Used for text 3. Boolean: Logical type that can only be true or false → Used for taking decisions 4. Undefined: Value taken by a variable that is not yet defined (‘empty value’) 선언했지만 밸류 할당하지 않은 데이터 타입 ex) let chil..