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 is the meaning of javascript variable

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)05/31 Report--

This article mainly introduces the relevant knowledge of "what is the meaning of javascript variable". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "what is the meaning of javascript variable" can help you solve the problem.

Variables in javascript are "containers" for storing information; JavaScript variables can be used to store values and expressions; and JavaScript variables can also hold other data types, such as text values.

This article operating environment: windows7 system, javascript1.8.5 version, Dell G3 computer.

The meaning of javascript variable

Variables are "containers" used to store information.

Example

Var xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

Just like algebra.

X=5y=6z=x+y

In algebra, we use letters (such as x) to preserve values (such as 5).

From the expression z=x+y above, we can calculate that the value of z is 11.

In JavaScript, these letters are called variables.

Lamp you can think of variables as containers for storing data.

JavaScript variable

Like algebra, the JavaScript variable can be used to store values (such as XForm5) and expressions (such as z=x+y).

Variables can use short names (such as x and y) or more descriptive names (such as age, sum, totalvolume).

Variables must start with a letter

Variables can also start with the $and _ symbols (although we do not recommend this)

Variable names are case-sensitive (y and Y are different variables)

Both lamp JavaScript statements and JavaScript variables are case-sensitive.

JavaScript data type

JavaScript variables can also hold other data types, such as text values (name= "Bill Gates").

In JavaScript, a text like "Bill Gates" is called a string.

There are many types of JavaScript variables, but for now, we only focus on numbers and strings.

When you assign a text value to a variable, you should surround the value in double or single quotes.

Do not use quotation marks when you assign a numeric value to a variable. If you enclose a numeric value in quotation marks, the value is treated as text.

Example

Var pi=3.14; / / if you are familiar with ES6,pi, you can use the const keyword to denote a constant / / const pi=3.14; var person= "John Doe"; var answer='Yes I am familiar'

Declare (create) JavaScript variables

Creating variables in JavaScript is often referred to as "declaring" variables.

We use the var keyword to declare variables:

Var carname

After the variable is declared, the variable is empty (it has no value).

To assign a value to a variable, use the equal sign:

Carname= "Volvo"

However, you can also assign values to variables when you declare them:

Var carname= "Volvo"

In the following example, we create a variable named carname, assign a value of "Volvo" to it, and put it in the HTML section of id= "demo":

Example

Var carname= "Volvo"; document.getElementById ("demo") [xss_clean] = carname; on "what is the meaning of the javascript variable" is introduced here, thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

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

Internet Technology

Wechat

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

12
Report