1. Primitive Type(์›์‹œ ํƒ€์ž…)
    • string
    • number
    • biginit
    • boolean
    • undefined
    • symboll
    • null
    • ์žฌํ• ๋‹น ํ•˜๋”๋ผ๋„, ์ฒ˜์Œ ํ• ๋‹นํ–ˆ๋˜ ๊ฐ’์ด ๋ฐ”๋€Œ์ง€ ์•Š์Œ
  2. Reference Type(์ฐธ์กฐ ํƒ€์ž…)
    • function
    • array
    • object
    • ์žฌํ• ๋‹นํ•˜๋ฉด, ๋ชจ๋“  ๊ฒƒ์ด ์ž๋™์ ์œผ๋กœ ๋‹ค ๋ฐ”๊ฟ”๋ฒ„๋ฆผ
    • save inside 'heap'
      1
      2
      console.log([1,2,3=== [1,2,3]; // false 
      console.log({ foo: 'ba' } === { foo: 'ba' }); // false
      cs
  3. 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
      1.  Local Scope vs. Global Scope
        • Local Scope 
          • 'Local Variable'(์ง€์—ญ๋ณ€์ˆ˜) has higher priority than global variable and cannot use it outside function
            1
            2
            3
            4
            5
            6
            7
            8
            let greeting = 'Hi';
            function greet() {
                let greeting = 'Hello';
                console.log(greeting); // 'Hello'
            }
            console.log(greeting); // 'Hi'
            greet();
            console.log(greeting); // 'Hi'
            cs
            1
            2
            3
            4
            function greetSomeone() {
            let firstName = 'Paige';
            return greeting + ' ' + firstName;
            }
            cs
        • Global Scope
          • 'Global Variable'(์ „์—ญ๋ณ€์ˆ˜) can access everywhere
            1
            2
            3
            4
            5
            6
            7
            8
            let greeting = 'Hi';
            function greetSomeone() {
            let firstName = 'Paige';
            return greeting + ' ' + firstName;
            }
             
            greetSomeone(); // => Hi Paige'
            firstName; // => ReferenceError
            cs
      2. 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(์žฌ์„ ์–ธ) โŒ โŒ โŒ
      3. 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!
          1
          2
          3
          4
          5
          6
          7
          8
          var myName = "Paige";
          console.log(window.myName); // Paige
           
          function foo() {
          console.log('bar');
          }
           
          console.log(foo === window.foo); // true
          cs
      4. No Declaration(์„ ์–ธ์—†์ด ์ดˆ๊ธฐํ™”๋œ ์ „์—ญ๋ณ€์ˆ˜)
        • do not use variable without assignment
        • if it does, it becomes global variable(์ „์—ญ๋ณ€์ˆ˜)
        • In order to avoid error, use 'use strict'
          1
          2
          3
          4
          5
          6
          7
          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)'
      1
      2
      3
      4
      function pintMaxNums(...args) { 
          console.log(args); //[10, 30, 40]
      }
      pintMaxNums(103040); 
      cs

       

'TIL' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

TIL 2020.11.05  (0) 2020.11.05
TIL 2020.11.04  (0) 2020.11.04
TIL 2020.11.02  (0) 2020.11.02
TIL 2020.11.01  (0) 2020.11.01
TIL 2020.10.30  (0) 2020.10.30

+ Recent posts