πŸ“
til
  • TIL(Today I Learned)
  • javascript
    • value-number-string-boolean-null-undefined
    • primitive-reference
    • Hoisting
    • Prototypes in Javascript
    • this
    • prototype
    • μ½œλ°±ν•¨μˆ˜ (Callback function)
    • ν•¨μˆ˜μ˜ 호좜
    • 자료ꡬ쑰 new keyword
    • closure
    • Promise
    • event-loop
    • array-object
    • 객체
    • Arguments
    • higher order function
    • operators-function-control-flow
    • 객체 생성 νŒ¨ν„΄ 3κ°€μ§€
    • Javascript scopes
    • Functional Programming
    • Design Patterns
    • 데이터 νƒ€μž…
    • Object 객체
    • ν‘œμ€€ λ‚΄μž₯ 객체의 ν™•μž₯
    • μ°Έμ‘°
    • ν•¨μˆ˜
    • 상속(Inheritance)
    • this - 'this'λ₯Ό μ‚¬μš©ν•˜λŠ” ν•΄λ‹Ή ν•¨μˆ˜λ₯Ό 'μ–΄λ–»κ²Œ' μ‹€ν–‰ν•˜λŠλƒμ— λ”°λ₯Έ 4κ°€μ§€ this μ •μ˜
    • 전역객체(Global object)
    • 객체 μ§€ν–₯ ν”„λ‘œκ·Έλž˜λ°
    • The 'new' keyword - Object Creation in JavaScript
  • javascript-api
    • Number
      • Number.MAX_VALUE
      • Number.isInteger
      • Number.NEGATIVE_INFINITY
      • Number.isNaN()
      • Number.POSITIVE_INFINITY
      • Number.parseFloat
      • Number.EPSILON
      • number.toExponential
      • Number.MAX_SAFE_INTEGER
      • Number1 - μžμ—°μˆ˜, μ •μˆ˜, 10μ§„μˆ˜, 2μ§„μˆ˜, λΆ€λ™μ†Œμˆ˜μ , μ‹€μˆ˜
      • Number.isSafeInteger()
      • Number.MIN_VALUE
      • Number.parseInt
      • Number.NaN
      • Number.isFinite()
      • Number.MIN_SAFE_INTEGER
      • toFixed
    • string.split
    • String.fromCodePoint
    • string.trimEnd
    • string.padStart
    • string.@@iterator
    • String.fromCharCode
    • string.toUpperCase
    • string.codePointAt
    • string.toLowerCase()
    • string.toString
    • string.includes
    • string.replace()
    • string.charAt
    • String.lastIndexOf
    • string.slice
    • string.search
    • string.padEnd
    • string.substring
    • string.length
    • string.trim
    • string.localeCompare
    • String.indexOf
    • string.endsWith
    • string.valueOf
    • String.raw
    • string.matchAll()
    • string.repeat
    • string.match
    • String.prototype
    • string.startsWith
    • string.charCodeAt
    • string.trimStart
    • string.concat
    • string.toLocaleUpperCase()
    • string.toLocaleLowerCase
    • String
  • learn-node
    • debugger
    • Tip
  • schema-design
    • Database Schema Design
    • Database Schema Design
  • react
    • LifeCycle
    • redux
    • Context API
    • ν•¨μˆ˜ν˜• μ»΄ν¬λ„ŒνŠΈμ™€ 클래슀, μ–΄λ–€ 차이가 μ‘΄μž¬ν• κΉŒ?
    • Hooksκ³Ό useEffect μ‚¬μš©ν•΄ 보기
    • Route
    • async wait μ‚¬μš©ν•˜κΈ°
    • Hooks API Reference
    • context
    • npm uninstall ν•˜λŠ”λ²•
    • test λ§Œλ“€κΈ°
  • tip
    • ν΄λ¦°μ½”λ“œ
    • BxSlider둜 ν…μŠ€νŠΈ 흐λ₯΄λŠ” 효과 λ§Œλ“€κΈ°
  • javascript30
    • Event Capture, Propagation, Bubbling and Once
    • Object and Arrays - Reference VS Copy
  • typescript
    • μš°μ•„ν•œ νƒ€μž…μŠ€ν¬λ¦½νŠΈ 2λΆ€
    • The Basic Cheatsheet
    • TypeScript
    • Type Guards and Differnetiating Types
    • μš°μ•„ν•œ νƒ€μž…μŠ€ν¬λ¦½νŠΈ
    • Generics
  • git-from-the-hell
    • git
    • init-status-add-commit-log-stage-repository
    • log-diff
    • λ¨Έμ§€ ν›„ branch μ‚­μ œν•˜κΈ°
    • μ§€μ˜₯μ—μ„œ 온 Git
    • reset-revert
    • develop branch λ₯Ό pull ν•˜κ³  μ‹Άμ„λ•Œ
  • conference-and-seminar
    • λͺ¨λ˜ ν”„λ‘ νŠΈμ—”λ“œ κ°œλ°œν™˜κ²½μ˜ 이해
  • fire-base
    • Firebase .gitignore
  • vanillacoding
    • Data Structures
    • Sorting Algorithms - part 1
    • Promise
    • class
    • 04.quiz
    • 07.event-loop
    • Design Patterns
    • OOP (Object Oriented Programming)
  • etc
    • μ•Œκ³ λ¦¬μ¦˜ μ½”λ“œλ¦¬λ·°
    • 슀슀둜 κ³΅λΆ€ν•˜λŠ” 법
    • 바닐라코딩 μˆ˜κ°• ν›„κΈ°
    • async 과제 ν›„κΈ° - 비동기, 동기, ν΄λ‘œμ €, λ°°μ—΄κ³Ό 객체
    • μœ μš©ν•œ μ‚¬μ΄νŠΈ
  • algorithm
    • The Supermarket Queue
    • Find the odd int
    • The Office III - Broken Photocopier
    • Directions Reduction
    • The Office II - Boredom Score
    • Divisible Sum Pairs
    • Codewars 이용자 μ†”λ£¨μ…˜ λͺ¨μŒ
    • Shortest Word
    • find key
    • Two Sum
    • Simple Pig Latin
  • Book
    • the essence of object-orientation
      • νƒ€μž…κ³Ό 좔상화
      • 객체 지도
      • μ΄μƒν•œ λ‚˜λΌμ˜ 객체
      • 좔상화 기법
      • 05. μ±…μž„κ³Ό λ©”μ‹œμ§€
      • 07.ν•¨κ»˜ λͺ¨μœΌκΈ°
      • 04. μ—­ν• , μ±…μž„, ν˜‘λ ₯
      • ν˜‘λ ₯ν•˜λŠ” κ°μ²΄λ“€μ˜ 곡동체
  • ecma-script2015
    • Object Literal Upgrades
    • default-parameter-template-literals-arrow-functions
    • spread-operator-rest-param
    • let-const-rest-parameter-spread-operator-destructuring
  • http
    • μ›Ή λΈŒλΌμš°μ €μ— URL을 μž…λ ₯ν–ˆμ„ λ•Œ μ–΄λ–»κ²Œ μ›Ή νŽ˜μ΄μ§€κ°€ λ³΄μ—¬μ§ˆκΉŒ?
  • jest
    • toThrow(error?)
  • data-structures
    • Data Structures
  • express
    • express generator
    • CORS
  • css-flexible-box-layout
    • flex 해버렸지 뭐야
  • git
    • Git
  • mongodb
    • MongoDB
  • markdown
    • use-markdown
  • cmder
    • cmd λͺ…λ Ήμ–΄ λͺ¨μŒ
  • debug
    • trackClicksEx function error
  • npm
    • NPM TOKEN μ„€μ •ν•˜κΈ°
  • storybook
    • Storybook
  • sort
    • Sorting Algorithms - part 1
  • javascript-koans
    • Javascript Koans μ˜€λ‹΅λ…ΈνŠΈ
  • rxjs
    • Rx.js
  • dom-elements
    • HTML Element
  • redux-toolkit
    • Redux Toolkit
  • github-actions
    • GitHub Actions
  • redux-middleware
    • redux middleware
  • rest
    • rest
  • css-rendering
    • μ½”λ“œ μŠ€ν”ΌμΈ  - CSS Rendering 1회차 2/2
    • μ½”λ“œ μŠ€ν”ΌμΈ  - CSS Rendering 1회차 1/2
  • you-dont-know-js
    • νƒ€μž…
  • server
    • # shutdown local server
  • semantic-versioning
    • Semantic Versioning 2.0.0
Powered by GitBook
On this page
  • Function Expressin ν•¨μˆ˜ ν‘œν˜„μ‹
  • Function Declaration ν•¨μˆ˜ 선언식
  • hoisting λ˜λŠ”κ±΄ 본인이 μ†ν•œ scope κΉŒμ§€ λŒμ–΄μ˜¬λ €μ§„λ‹€.
  • Quiz

Was this helpful?

  1. javascript

Hoisting

μžμ‹ μ΄ μ†ν•œ scopeμ—μ„œ μ΅œμƒλ‹¨κΉŒμ§€ λŒμ–΄μ˜¬λ¦°λ‹€.

console.log(a);//error

μ •μ˜λ˜μ§€ μ•Šμ€ aλ₯Ό 찾을 땐 error κ°€ λœ¬λ‹€.

console.log(a); //undefined
var a = 1;
console.log(a); //1

첫번째 console.log(a) μ—μ„œ errorκ°€ μ•ˆλ‚˜κ³  undefinedκ°€ λ‚˜μ˜¨λ‹€. 이게 λ°”λ‘œ Hoisting 'ㅁ'/ Hoisting을 톡해 μžλ°”μŠ€ν¬λ¦½νŠΈκ°€ μœ„μ—μ„œ μ•„λž˜κΉŒμ§€ μ­‰ 읽어 λ‚΄λ €κ°€κΈ°λ§Œ ν•œλ‹€λŠ”κ²Œ μ•„λ‹ˆλΌλŠ”κ±Έ μ•Œ 수 μžˆλ‹€.

var a 
console.log(a);
a = 1;
console.log(a);

μ΄λ ‡κ²Œ 된거라고 μƒκ°ν•˜λ©΄ 쉽닀. λŒμ–΄μ˜¬λ €μ„œ 미리 λ³€μˆ˜λ₯Ό μ •μ˜ν–ˆμ§€λ§Œ 값은 μ œμžλ¦¬μ—μ„œ 넣어짐

전체가 λŒμ–΄μ˜¬λ €μ§€λŠ”κ²Œ μ•„λ‹ˆλΌ λ³€μˆ˜μ— λŒ€ν•œ μ„ μ–ΈλΆ€λΆ„λ§Œ λŒμ–΄μ˜¬λ €μ§„λ‹€.

console.log(a);
var a = 1;
console.log(a);
foo();
function foo(){
    console.log(a);
}

foo() ν•¨μˆ˜λŠ” λ¬Έμ œμ—†μ΄ μ‹€ν–‰λœλ‹€.

bar();

var b = 1;

function bar(){
    if (false) {
        b = 2;
    } else {
        console.log(b);
    }
}
console.log(b);

bar()λ₯Ό μ‹€ν–‰ν•˜λ©΄ console.log(b)κ°€ μ°νžˆλŠ”λ° bλŠ” 아직 μ •μ˜ 되기 μ „ ν•¨μˆ˜λ₯Ό ν˜ΈμΆœν•˜μ˜€λ‹€. ν•˜μ§€λ§Œ ν˜Έμ΄μŠ€νŒ…μœΌλ‘œ var b κ°€ λ¨Όμ € 선언이 λ˜μ–΄ 있기 λ•Œλ¬Έμ— undefinedκ°€ λœ¬λ‹€.

var b;

bar(); // undefined

b = 1;

function bar(){
    if (false) {
        b = 2;
    } else {
        console.log(b);
    }
}
console.log(b); //1

μ΄λŸ°μ‹μœΌλ‘œ μƒκ°ν•˜λ©΄ 쉽닀.

Function Expressin ν•¨μˆ˜ ν‘œν˜„μ‹

d();

var d = function () {
  console.log('I am inside function d');  
};

λ³€μˆ˜λ‘œ μ •μ˜ν•˜κ³  ν•¨μˆ˜λ₯Ό ν• λ‹Ήν•΄ μ€€λ‹€. d()λŠ” undefinedκ°€ λ‚˜μ˜¨λ‹€. μ™œλƒν•˜λ©΄ var d κΉŒμ§€λ§Œ hoisting 되기 λ•Œλ¬Έμ΄λ‹€.

var d;

d();

d = function () {
  console.log('I am inside function d');  
};

이와 λΉ„μŠ·ν•˜λ‹€κ³  μƒκ°ν•˜λ©΄ μ’‹λ‹€.

Function Declaration ν•¨μˆ˜ 선언식

j();

function j (){
    console.log('j');
}

μ„ μ–Έμ‹μœΌλ‘œ 적은건 ν•¨μˆ˜ μžμ²΄κ°€ hoisting λœλ‹€. νšŒμ‚¬ μ»¨λ²€μ…˜μ— λ§žμΆ”μ–΄ μž‘μ—…ν•˜λ©΄ λœλ‹€.

ν•¨μˆ˜ 선언식은 μ„Έλ―Έμ½œλ‘ (;)을 찍지 μ•ŠλŠ”λ‹€.

var e = 2;
var d = function () {};

function j () {
    console.log('j');
} //이 뢀뢄에 μ„Έλ―Έμ½œλ‘ μ„ 찍지 μ•ŠλŠ”λ‹€.

hoisting λ˜λŠ”κ±΄ 본인이 μ†ν•œ scope κΉŒμ§€ λŒμ–΄μ˜¬λ €μ§„λ‹€.

var me = 'sla';

function foo () {
    alert(me);

    var me = 'someone else';
}

foo();
var me = 'sla';

function foo () {
    var me;
    alert(me);

    me = 'someone else';
}

foo();

κ·Έλž˜μ„œ undefinedκ°€ λœ¬λ‹€.

Quiz

function foo() {
    return
    {
      age: 30  
    };
}

console.log(typeof foo());

undefinedκ°€ λœ¬λ‹€. return ꡬ문은 κ°œν–‰ν•΄μ„œλŠ” μ•ˆλ˜μ„œ..

var arr = ['hello', 'world'];
arr[a] = 'thank you';
console.log('2' in arr);

인덱슀 in arr 인데 μΈλ±μŠ€λ„ κ²°κ΅­ 문자라 싀행이 λœλ‹€.

Previousprimitive-referenceNextPrototypes in Javascript

Last updated 5 years ago

Was this helpful?