Wednesday 8 November 2017

javascript function vs var function


The difference is that start is a function expression and so only defined when that line is reached, whereas M is a function declaration and is defined as soon as its surrounding function or script is executed.
For example, a function expression:
// TypeError: undefined is not a function
start();
var start=function(){
    console.log("Start function called !");
}
//It will work 
m();
 function m() {
    console.log("Function M is working fine");
   
}