August 2016
Intermediate to advanced
635 pages
14h 5m
English
We saw two ways by which functions are defined. Though they both serve identical purposes, there is a difference between these two types of declarations. Check the following example:
//Function expression
functionOne();
//Error
//"TypeError: functionOne is not a function
var functionOne = function() {
console.log("functionOne");
};
//Function declaration
functionTwo();
//No error
//Prints - functionTwo
function functionTwo() {
console.log("functionTwo");
}A function declaration is processed when execution enters the context in which it appears before any step-by-step code is executed. The function that it creates is given a proper name (functionTwo() in the preceding example) and this name is put ...