Java Script | Anonymous Functions & 'Self-invoking' [how to create and return values from functions]

preview_player
Показать описание
Function Expressions
A JavaScript function can also be defined using an expression.

The video explains that functions can be assigned to variables, and the variable can be used to call the function. They show an example of assigning a function to a variable called "total" and then calling the function using the variable name. However, they encounter an error because the function name is eliminated when assigning the function to a variable. They resolve this issue by using the variable name instead of the function name when calling the function.

The instructor then demonstrates how to create self-invoking functions. They show two ways to achieve this: by placing parentheses before and after the function name, or by immediately invoking the function after declaring it. They explain that self-invoking functions allow for declaring and calling a function simultaneously. Finally, they show an example of a self-invoking function that returns a value and assign the return value to a variable for display.

Overall, the video covers the topics of creating functions, assigning functions to variables, calling functions using variables, and creating self-invoking functions.
====================================================
A function expression can be stored in a variable:

Example
const x = function (a, b) {return a * b};
==================================================
A self-invoking (also called self-executing) function is a nameless (anonymous) function that is invoked immediately after its definition. ... A self-invoking function can have variables and methods but they cannot be accessed from outside of it.
Рекомендации по теме
visit shbcf.ru