Function Expressions
A JavaScript function can also be defined using an expression.
In this video, the instructor discusses functions in JavaScript and how to create and return values from functions. They demonstrate how to get user input using the window.prompt method and display the result in the console.log statement. The instructor also introduces the concept of anonymous functions and self-invoking functions.
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.
On this page of the site you can watch the video online Java Script | Anonymous Functions & "Self-invoking" [how to create and return values from functions] with a duration of hours minute second in good quality, which was uploaded by the user Techno_Coder 12 October 2021, share the link with friends and acquaintances, this video has already been watched 1,874 times on youtube and it was liked by 5 viewers. Enjoy your viewing!