In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly shows you "what is the difference between var,let and const in JavaScript". The content is simple and clear. I hope it can help you solve your doubts. Let me lead you to study and learn this article "what is the difference between var,let and const in JavaScript".
What is the difference between var,let and const?
Variables declared by var are mounted on window, while variables declared by let and const are not:
Var a = 100 undefinedconst console.log (a undefinedconst window.a); / / 100 undefined b = 10 undefinedconst console.log (bline window.b); / / 10 console.log (cdepartment window.c); / / 1 window.log
Var declares that there is variable promotion in variables, and there is no variable promotion in let and const:
Console.log (a); / / undefined = > a has been declared unassigned, and the default value is var a = 100 console.log (b); / / error: b is not defined = = > cannot find the variable b, let b = 10 console.log (c); / / error: c is not defined = = > cannot find the variable const c = 10
Let and const declarations form block scope
If (1) {var a = 100; let b = 10;} console.log (a); / / 100console.log (b) / / error: b is not defined = = > the variable b cannot be found-if (1) {var a = 100 Const c = 1;} console.log (a); / / 100console.log (c) / / error: c is not defined = = > the variable c cannot be found
Let and const cannot declare variables with the same name in the same scope, but var can
Var a = 100 100var console.log (a); / / 10--let a = 10 position console.log (a); / / 10--let a = 100 let a = 10 bank / console error: Identifier 'a'console.log = > identifier a has been declared.
Temporary dead zone
Var a = 100 10 if (1) {a = 10; / / if an is declared using let/const in the current block scope, assigning an at 10:00 will only find the variable an in the current scope, / / and at this time, it is not yet time to declare, so the console Error:an is not defined let a = 1;}
Const
/ * * 1. Once it is declared that a value must be assigned, you cannot use null to occupy a place. * * 2. Cannot be modified after declaration * * 3. If you are declaring compound type data, you can modify its properties * * / const a = 100; const list = []; list [0] = 10 const obj console.log (list); / / [10] const obj = {aura 100}; obj.name = 'apple';obj.a = 10000 console.log (obj) The above are all the contents of this article entitled "what is the difference between var,let and const in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.