Scope

Primitive Type(원시 타입)

  • string
  • number
  • biginit
  • boolean
  • undefined
  • symboll
  • null
  • 재할당 하더라도, 처음 할당했던 값이 바뀌지 않음

Reference Type(참조 타입)

  • function
  • array
  • object
  • 재할당하면, 모든 것이 자동적으로 다 바꿔버림
  • save inside ‘heap’

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

Global Scope

  • ‘Global Variable’(전역변수) can access everywhere

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

Global Variable(전역변수) and Window object(윈도우객체)

  • will connect to function that is assigned at global scope and var variable
  • do not declare too much in global scope!

No Declaration(선언없이 초기화된 전역변수)

  • do not use variable without assignment
  • if it does, it becomes global variable(전역변수)
  • In order to avoid error, use ‘use strict’

--

--

--

Consistency achieves everything https://github.com/paigekim29

Love podcasts or audiobooks? Learn on the go with our new app.

JavaScript, 10 Basic String Methods are Simplified

Understanding Asynchronous JavaScript

HTML, CSS & JavaScript

How to add select2 multiple selector in django app (Deadly simple way)

End result: Select2 multiselect dropdown in django app

10 Crucial JavaSctipt’s Method You Should Know!

How to set and update cell contents in an Excel XLSX by index in Node.JS

JavaScript Basics

duckett books for html css & javascript

How to Reduce PDF File Size in JavaScript

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Joo Hee Paige Kim

Joo Hee Paige Kim

Consistency achieves everything https://github.com/paigekim29

More from Medium

Logical Assignment Operators in JavaScript

Day 3 of 165~Reversing Arrays Without Using .reverse()

Hoisting in Javascript

Rx.js Observables