Functions Flashcards

1
Q

Function definition. Blocks. Function expression vs Function declaration.

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do arguments get passed into the function

A

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’) { … }]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly