paigekim29
2020. 11. 3. 09:40
2020. 11. 3. 09:40
- Primitive Type(์์ ํ์
)
- string
- number
- biginit
- boolean
- undefined
- symboll
- null
- ์ฌํ ๋น ํ๋๋ผ๋, ์ฒ์ ํ ๋นํ๋ ๊ฐ์ด ๋ฐ๋์ง ์์
- Reference Type(์ฐธ์กฐ ํ์
)
- function
- array
- object
- ์ฌํ ๋นํ๋ฉด, ๋ชจ๋ ๊ฒ์ด ์๋์ ์ผ๋ก ๋ค ๋ฐ๊ฟ๋ฒ๋ฆผ
- save inside 'heap'
|
console.log([1,2,3] === [1,2,3]; // false
console.log({ foo: 'ba' } === { foo: 'ba' }); // false
|
cs |
- SCOPE(๋ฒ์)
- determines the accessibility of variables
- JS receive own scope once function was created, which is lexical scope
- check who is its outer scope
- can put function inside function
- Local Scope vs. Global Scope
- Local Scope
- 'Local Variable'(์ง์ญ๋ณ์) has higher priority than global variable and cannot use it outside function
|
let greeting = 'Hi';
function greet() {
let greeting = 'Hello';
console.log(greeting); // 'Hello'
}
console.log(greeting); // 'Hi'
greet();
console.log(greeting); // 'Hi'
|
cs |
|
function greetSomeone() {
let firstName = 'Paige';
return greeting + ' ' + firstName;
}
|
cs |
- Global Scope
- 'Global Variable'(์ ์ญ๋ณ์) can access everywhere
|
let greeting = 'Hi';
function greetSomeone() {
let firstName = 'Paige';
return greeting + ' ' + firstName;
}
greetSomeone(); // => Hi Paige'
firstName; // => ReferenceError
|
cs |
- Function Scope vs. Block Scope
- Block
- starts and end with curly bracket { }
- var vs. let
- var: gets its own scope (old way)
- connects with window object
- let: only works inside block scope
|
let |
const |
var |
scope |
block scope |
block scope |
function scope |
reassignment(์ฌํ ๋น) |
โญ๏ธ |
โ |
โ |
redeclaration(์ฌ์ ์ธ) |
โ |
โ |
โ |
- Global Variable(์ ์ญ๋ณ์) and Window object(์๋์ฐ๊ฐ์ฒด)
- will connect to function that is assigned at global scope and var varible
- do not declare too much in global scope!
|
var myName = "Paige";
console.log(window.myName); // Paige
function foo() {
console.log('bar');
}
console.log(foo === window.foo); // true
|
cs |
- No Declaration(์ ์ธ์์ด ์ด๊ธฐํ๋ ์ ์ญ๋ณ์)
- do not use variable without assignment
- if it does, it becomes global variable(์ ์ญ๋ณ์)
- In order to avoid error, use 'use strict'
|
function showAge() {
age = 24;
console.log(age);
}
showAge(); // 24
console.log(age); // 24
age === window.age
|
cs |
- Spread Syntax(...variable)
- if spread syntax goes inside parameter, it become 'rest parameter(rest syntax)'
|
function pintMaxNums(...args) {
console.log(args); //[10, 30, 40]
}
pintMaxNums(10, 30, 40);
|
cs |
'TIL' ์นดํ
๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ