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 ​ JavaScript variables and data types

2025-03-29 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article is about what JavaScript variables and data types are. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

JavaScript variable

A variable is a container for storing information.

Just like algebra, we can calculate the value of z as 5.

In JavaScript, these letters are called variables. You can think of variables as containers for storing data.

Var xylene 2; var yearly 3; var zodiac 2 # 3; [xss_clean] (x + "

"); [xss_clean] (y +"

"); [xss_clean] (z +"

")

JavaScript variable

Like algebra, the JavaScript variable can be used to store values (such as XForm2) 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).

Variables must start with a letter. Variables can also start with the $and _ symbols (although this is not recommended).

Variable names are case-sensitive (y and Y are different variables). JavaScript statements and 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. Otherwise, the value is treated as text.

Var pi=3.14; var name= "Bill Gates"; var answer= "Yes I am!"; [xss_clean] (pi + "

"); [xss_clean] (name +"

"); [xss_clean] (answer +"

")

Declare (create) JavaScript variables

Creating variables in JavaScript is often referred to as "declaring" variables. 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"

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

Click here to create the variable and display the result.

Click here.

Function myFunction () {var yard5; var xroomyroom2; var demoP=document.getElementById ("demo") demoP [XSS _ clean] = "x =" + x;} Thank you for reading! This is the end of the article on "what are JavaScript variables and data types". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

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