Function features

Слайд 2

AGENDA Arrow functions Default parameters IIFE

AGENDA

Arrow functions
Default parameters
IIFE

Слайд 3

ARROW FUNCTIONS An arrow function expression is a syntactically compact alternative to a regular function expression

ARROW FUNCTIONS

An arrow function expression is a syntactically compact alternative to

a regular function expression
Слайд 4

ARROW FUNC vs REGULAR FUNC An arrow function has not its

ARROW FUNC vs REGULAR FUNC

An arrow function has not its own

bindings to the:
this,
arguments,
super
Arrow function expressions are ill suited as methods, and they cannot be used as constructors.
Слайд 5

COMPACT FORM If we have single line operation in function, we

COMPACT FORM

If we have single line operation in function, we can

use short-compact form of arrow function without {} and return
Слайд 6

DEFAULT PARAMETERS Default function parameters allow named parameters to be initialized

DEFAULT PARAMETERS

Default function parameters allow named parameters to be initialized with

default values if no value or undefined is passed.
Слайд 7

WHY WE NEED THIS? Function parameters default to undefined. However, it's

WHY WE NEED THIS?

Function parameters default to undefined. However, it's often

useful to set a different default value. This is where default parameters can help.
Слайд 8

BEFORE DEFAULT PARAMETERS Examples of expressions that can be converted to

BEFORE DEFAULT PARAMETERS

Examples of expressions that can be converted to false

are:
null,
NaN,
0,
empty string ("" or '' or ``),
undefined.

|| (OR) operator can be used with operands that are not Boolean values, it can still be considered a boolean operator since its return value can always be converted to a boolean primitive.

Слайд 9

IIFE An IIFE (Immediately Invoked Function Expression) is a JavaScript function

IIFE

An IIFE (Immediately Invoked Function Expression) is a JavaScript function that

runs as soon as it is defined.
Слайд 10

SELF-EXECUTING ANONYMOUS FUNCTION It is a design pattern which is also

SELF-EXECUTING ANONYMOUS FUNCTION

It is a design pattern which is also known

as a Self-Executing Anonymous Function and contains two major parts:
The first is the anonymous function with lexical scope enclosed within the Grouping Operator (). This prevents accessing variables within the IIFE idiom as well as polluting the global scope.
The second part creates the immediately invoked function expression () through which the JavaScript engine will directly interpret the function.