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 methods of declaring variables without var by javascript

2025-03-29 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 ways in which javascript declares variables without var". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "what are the ways in which javascript declares variables without var?"

Javascript declares variables without var. You can use the let and const keywords. Let and const are two new ways to declare variables in the ECMAScript6 version. You can declare block-level scoped variables using let. Variables declared with const are similar to let variables, but cannot be reassigned.

The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.

There are three ways to declare JavaScript variables, using the var, let, and const keywords. Javascript declares variables without var, but can also use the let and const keywords.

Among them, the two ways in which let and const declare variables are new in the ECMAScript6 version.

1. Declare variables using var

Using var, you can declare variables with global or function-level scope, and there are several ways to declare syntax.

Mode 1: var variable name; Mode 2: var variable name 1, variable name 2, … , variable name n; method 3: var variable name 1 = value 1, variable name 2 = value 2,... , variable name n = value n

1) using var, you can declare one variable at a time, or you can declare multiple variables at a time, separated by commas. For example:

Var name; / / declare one variable at a time var name,age,gender; / / declare multiple variables at a time

2) you can declare a variable without initialization (that is, assigning an initial value). At this time, the default value is undefined;, or you can initialize the variable while declaring the variable. For example:

Var name = "Zhang San"; / / initialize variables var name = "Zhang San", age=20,gender; / / initialize some variables var name = "Zhang San", age=20,gender = 'female' in one declaration; / / initialize all variables in one declaration

3) the specific data type of the variable is determined according to the data type of the assigned value, for example:

Var message = "hello"; / / value is a string type, so the type of message variable is string type var message = 123; / / value is numeric, so the type of message variable is numeric type Var message = true;// value is Boolean type, so the type of message variable is Boolean type

4) in practical applications, the declaration of loop variables is often directly regarded as part of the loop syntax. For example:

For (var iTuno Bandi)

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