Function Statement
: initially put in to memory, but have to invoke it for it to execute
함수 선언식은 항상 상단으로
show();
function show() {
console.log('displayed!');
}
Function Expression( not hoisted )
+ ( parameter ) = Immediately Invoked Function Expression(IIFE)
: A unit of code that results in a value
not initially put in to memory, when it hits this line it creates this function object on the fly.
It doesn't have to save to a variable
함수 표현식은 할당된 변수만 상단으로 Hoisting
show(); // <TypeError> show is not a function
var show = function() {
console.log('displayed!');
}
IIFE
var firstname = "John";
(function(name) {
var greeting = "Inside IIFE: hello";
console.log(greeting + ' ' + name); > Inside IIFE: hello John
}(firstname));
IIFEs and Safe Code
Arguments
: The parameters you pass to function
Javascript gives you a keyword of the same name which contains them all
by value(primitives) / by reference(all objects (including functions)
equals operator sets up new memory space(new address)
'this'
Automatic Semicolon Insertion
Closure
First class functions & Closures
Everytime call a function it gets it own execution context. Any functions created inside of it will point that execution context
First Class Functions
: Everything you can do with other types you can do with functions.
Assign them to variables, pass them around, create them on the fly
Callback Function
: A function you give to another function, to be run when the other function is finished
So the function you call, 'calls back' by calling the function you gave it when it finishes
call(), apply(), bind() 복습하기
Functional programming > Underscore Library
Function Currying
: Creating a copy of a function but with some preset parameters
Very useful in mathematical situations
'Udemy > JavaScript:Understanding the weird part' 카테고리의 다른 글
The 'new' keyword (0) | 2019.03.08 |
---|---|
closure and keyword 'this' (0) | 2019.03.07 |
Object-Oriented Javascript and Prototypal Inheritance (0) | 2019.03.04 |
Types and Operators (0) | 2019.02.23 |
Execution Contexts and Lexical Environments (0) | 2019.02.22 |