We are here with you hands in hands to facilitate your learning & don't appreciate the idea of copying or replicating solutions. Read More>>


Looking For Something at vustudents.ning.com? Click Here to Search

JavaScript ES6, use of "let" and "const"

JavaScript is most commonly used as a client side scripting language.
var keyword declares a variable in JavaScript language. We can define it anywhere within a function or on global level, as given below;

Note: comments/descriptions are in italic

var _currenCGPA = 3.10 // Define a Global variable
function oldCGPA(){ // Define a function
var _currenCGPA = 2.90 // it will redefined the variable, even we just give a value on local level but it will affect the variable on the global level.
}

End result is _currenCGPA = 2.90, we assigned a value within a function but it changed the value on global level

Description:
            Remember that var keyword can’t have block scope. If we declare a variable inside a block, still we can access that variable from outside the block/function.
            Because of this problem let and const keywords are introduced. Variables declared with let or const keywords cannot be accessed from outside the block, as given below;

var _currenCGPA = 3.10 // Define a Global variable
function oldCGPA(){ // Define a function
let _currenCGPA = 2.90 // this value will work only for this block/function, it won’t affect the variable on global level
}

End result is _currenCGPA = 3.10, we can see value didn’t change on the global level, no old CGPA assigned on the global level and that’s what we wanted.

This is work same for const keyword too. We can use these keywords in ES6.


+ Click Here To Join also Our facebook study Group.


..How to Join Subject Study Groups & Get Helping Material?..


See Your Saved Posts Timeline

Views: 29

.

+ http://bit.ly/vucodes (Vu Study Groups By Subject Codes Wise)

Comment

You need to be a member of Virtual University of Pakistan to add comments!

Join Virtual University of Pakistan

© 2019   Created by + M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service