Featured

    Featured Posts

What is ECMAScript 2015 or ES6

 

What is ECMAScript 2015 or ES6

Variables In ECMAScript:-

 §  Variables had two types of scope.

1.     Block scope

2.     Global scope

Global Scope:-

§  If we are declare any variable inside the file directly but outside of any function or         block that variable comes in global scope i.e. variables have global scope.

//global scope
var a=10;
console.log(a);
function f1()
{    
 console.log(a);
}
f1();

  §  If any variable have global scope that variable can be accessible anywhere in the program.

Function Scope:

§  If any variables that are declared inside a function then that variable have function       scope.
function f1()
{
   var a=10;
  console.log(a);
  }
  f1();
//we can't access varaible 'a' outside function
console.log(a);//error

Note:-

§  If any variable that have function scope that variable can be accessible only with-in function in which they are declared and that function can't be accessible outside the function.

//global scope
var a=10
function f1(){
//function scope
 var a=20;
console.log(a);//output:20
}
f1();
console.log(a);//output:10

Note:-

§  If variable having same name in global scope and function scope then if we access that   variable with in function then you will get function scope variable value but if you   access outside variable then you will be get global scope variable value.

Important Points:

§  Variables that are declared by using var kwd can't have block scope.

§  Variables declared inside a block {} can be access from outside the block.

 


author

Author Name

Author Description!

Get Free Email Updates to your Inbox!

Post a Comment

www.CodeNirvana.in

Powered by Blogger.

About

Site Links

Popular Posts

Translate

Total Pageviews