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

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

青灯夜游
青灯夜游forward
2018-10-23 17:28:452445browse

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}

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);

The printed values ​​are:

3;
1.5
Mark
true;
null;
undefined

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

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

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!

Statement:
This article is reproduced at:cnblogs.com. If there is any infringement, please contact admin@php.cn delete