Assigned to Variables

When a function is assigned to a variable it is often called a Function Expression or function literal.
Functions that are assigned to variables are Not Hoisted.

This function cannot be invoked using its name. You must use the variable name.
If you have assigned it to a variable you cannot call the function name.
The name of the function only exists inside the function scope, it is not accessbile outside.

var myVar = function add() { 
   return arguments[0] + arguments[1];

const myVar = function myFun(arg) { 

This is a named function expression

var checkNum = { 
'isEven' : function IsEven(num) {
      return num % 2 === 0;
console.log(checkNum.IsEven(2) ); // true

© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext