Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

How to use global variables correctly by javascript

Shulou Source: shulou.com Published: 2022-05-31 11:46:57 09月23日 Update

This article mainly explains "how to correctly use global variables in javascript". The content in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to correctly use global variables in javascript".

Description

1. If you want to access the outermost variable, that is, the global variable, it will cause a greater performance loss than directly accessing the internal variable.

2. Frequently used global variable references can be stored in a local variable.

Example

Const a = 5BX function outter () {const a = 2; function inner () {const b = 2; console.log (b); / / 2 console.log (a); / / 2} inner ();} JavaScript features 1.JavaScript is mainly used to add interactive behavior to HTML pages. 2.JavaScript can be embedded directly into HTML pages, but writing as a separate js file facilitates the separation of structure and behavior. 3.JavaScript has cross-platform features and can run on multiple platforms with the support of most browsers.

Thank you for reading, the above is the content of "how to correctly use global variables in javascript". After the study of this article, I believe you have a deeper understanding of how to correctly use global variables in javascript, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Variables global learning content behavior page outer layer variety examples that is local platform ideas performance situation files articles more favorable browser Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Huawei Linux vpn MySQL