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

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More


Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

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.

+ How to Follow the New Added Discussions at Your Mail Address?

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

+ How to become Top Reputation, Angels, Intellectual, Featured Members & Moderators?

+ VU Students Reserves The Right to Delete Your Profile, If?


See Your Saved Posts Timeline

Views: 53

.

+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)

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

.