Javascript Basic Concepts

Javascript Basic Concepts

Function Declarations vs Function Expressions

Function Declarations

Function declarations define named function variables without the need for variable assignments. Function declarations occur as independent components and can not be nested within non-function blocks. It is useful to think of them as siblings of variable declarations. Function declarations must begin with "function", as variable declarations begin with "var".

example :-

function testFunction(){
  console.log("Hello World");
}

To execute this function we can call it as " testFunction()



Function Expressions

 A function expression defines a function as part of the syntax of a larger expression (usually variable assignment). Functions defined by function expressions can be named or anonymous. Function expressions must not begin with "function"

example :- 

Anonymous function expression
var x = function(){
    return "Hello World";
}

Named function expression
var x = function testFunction(){
    return "Hello World";
}

Self invoking function expression
(function sayHello() {
alert("Hello World");
})();

Comments

Popular posts from this blog

Firebase Cloud Functions

NoSQL (Not Only SQL database)

React JS