Functions Flashcards
Function definition. Blocks. Function expression vs Function declaration.
Block is a group of statements surrounded by curly brackets.
Function is a named block we can call on demand.
Function expression: function name(args) { ... } - gets hoisted above other code, gets defined during parsetime Function declaration: let name = function(args) { ... } - gets defined during runtime
How do arguments get passed into the function
Primitive types [ number, string, bool, … ] get passed by value
Complex types [ Objects, Arrays, … ] get passed by a reference, so the passed argument can be modified inside the function body even if it’s not returned by the function.
All arguments of the classic function (not an arrow function) can be accessed by the keyword arguments that is an array-like structure.
In ES6 any functions arguments can be accessed using spread operator [function( …args) { … }]
In ES6 it is possible to set default parameters to a function [function(a = ‘a’) { … }]