Home > Web Front-end > JS Tutorial > What types of javaScript variables are there? How to declare variables

What types of javaScript variables are there? How to declare variables

青灯夜游
Release: 2018-10-23 17:28:45
forward
2473 people have browsed it

The content of this article is to introduce what types of javaScript variables are there? How to declare variables. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

JavaScript variable types include: numbers, strings, Boolean values, functions and objects. There are also undefined and null, as well as arrays, dates, and regular expressions.

var num = 1; //{1}
num = 3; //{2}
var price = 1.5; //{3}
var name = "Mark"; //{4}
var trueValue = true; //{5}
var nullVar = null; //{6}
var und; //{7}
Copy after login

In line 1, we declared a numeric type; although var is not necessary, it is best to declare it every time.

In line 2, we update num. This operation means that you can declare a variable and initialize it to a numeric value, and then update it to a string or other type of value. It's best not to do this.

In line 3, we declare a variable of numeric type as a decimal floating point number.

In line 4, we declare a string.

At line 5, a Boolean value is declared.

At line 6, a null is declared.

In line 7, the undefined variable is declared.

Note: null means the variable has no value, undefined means the variable has been declared but has not been assigned a value

If we want to see the value of each variable, console.log Print to view

console.log(num);
console.log(price);
console.log(name);
console.log(trueValue);
console.log(nullVar);
console.log(und);
Copy after login

The printed values ​​are:

3;
1.5
Mark
true;
null;
undefined
Copy after login

We can also print out anything we want to see through the console:

例如:console.log("小马今天起床到现在,什么都没吃呢!")
Copy after login

in chrome Just like this:

The above is the detailed content of What types of javaScript variables are there? How to declare variables. For more information, please follow other related articles on the PHP Chinese website!

source:cnblogs.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template