Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the improvements in js variables?

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "what are the improvements in js variables". The explanation in this article is simple and clear, easy to learn and understand. Please follow the ideas of Xiaobian to study and learn "what are the improvements in js variables" together.

Variable declared by var will be promoted to the top of the current scope, not global. Declarations only promote, assignments do not promote. Variables declared without var are hung by default under the global object window.

2, if it is a function variable promotion, equivalent to var add; add = function....

examples

//variable promoted to top of current scope function add(num1, num2) { console.log(sum); // undefined var sum = num1 + num2; return sum;}var result = add(10, 20); //30console.log (sum); //only variables will promote console.log(typeof(a)); // undefined, a is a variable that promotes console.log(typeof(b)); // function, b is a named function, the function as a whole promotes var a = function() { }function b() { }

Due to the increment of the variable, sum is promoted to varsum on the first line of the function; therefore, the first log is undefined. Moreover, the sum outside cannot be found until the global scope, so the error is not defined.

Thank you for your reading, the above is the content of "what are the improvements of js variables". After studying this article, I believe everyone has a deeper understanding of what improvements js variables have. The specific use situation still needs to be verified by practice. Here is, Xiaobian will push more articles related to knowledge points for everyone, welcome to pay attention!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report