JS中有多少种数据类型,它们是什么? [英] How many data types are there in JS, and what are they?
本文介绍了JS中有多少种数据类型,它们是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我开始读一本书,《 Javascript for Kids》.作者在其中指出了三种数据类型:
I started reading a book, Javascript for Kids. In it the author states that there are three data types:
- 数字
- 字符串
- 布尔值
但是,根据 W3Schools ,有四个:
- 数字
- 字符串
- 数组
- 对象
我想知道哪个是正确的.
I wanted to know which one is correct.
推荐答案
您可以使用 typeof
运算符对其进行测试:
You can test it using typeof
operator:
typeof
运算符可为您提供位于任何单个操作数之前的数据类型名称.
The typeof
operator gives you the names of data types when placed before any single operand.
因此,请尝试将 typeof
与任何操作数变量一起使用:它将给出以下数据类型名称之一:
Hence, try using typeof
with any operand variable: it will give one of the following datatype names:
- 字符串
- 号码
- 布尔值
- 对象
- 未定义
因此,这是Javascript中的五种数据类型.
Hence, these are the five data Types in Javascript.
var val1 = "New World"; //returns String
var val2 = 5; //returns Number
var val3 = true; //returns Boolean
var val4 = [1,2,3]; //returns Object
var val5 = null; //returns Object (Value is null, but type is still an object)
var val6; //returns Undefined
这篇关于JS中有多少种数据类型,它们是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文