JS data type

Source: Internet
Author: User

Data type
ECMAScript中有5种简单数据类型(也称为基本数据类型),1种复杂的数据类型基本数据类型    Undefined,Null,Boolean,Number和String复杂数据类型    Object本质是由一组无序的名值对组成
typeof operator
typeof 是一个操作符而不是函数,因此圆括号可以使用,但不是必须typeof 能检测基本数据类型的详细类型,但检测不出引用类型的详细类型undefined——值未定义boolean——布尔值string——字符串number——数值object——对象或nullfunction——函数
Undefined type
undefinde类型只有一个值即特殊的undefined在使用var变量并未对其初始化时,这个变量就是undefined1var messages;alert(message == undefined); //true2var message = undefined;alert(message == undefined); //true3var message//age 未声明alert(message) //undefindealert(age) //产生错误4var message// age 未声明alert( typeof message ) // undefinedalert( typeof age ) // undefined
Null type
null 值表示空指针对象,这也是 typeof 操作符检测 null 值时会返回“object”的原因如果定义的变量准备在将来用于保存对象,那么最好将该变量初始化为 nullBoolean 类型    该类型只有两个值 true 和 false    Boolean 会转变成 false 的值    Boolean 的 false    String 的 空字符串    Number 的 0和NaN    Object 的 null    Undefined 的 Undefined
Number Type
浮点数值    所谓浮点数值,就是该数值中必须包含一个小数点,并且小数点后面还有数字    由于保存浮点数值需要的内存空间是保存整数的两倍,因此 ECMAScript 会自动将浮点数值转换为整数数值范围    最大数值范围 5e-324    产出数值范围会自动换成特殊的 (正负)Infinity 值    isFinite() 函数。这个函数在参数位于最小与最大数值之间时会返回 true    NaN    NaN 即非数值(Not a Number)是一个特殊的值    NaN 值互不相等 alert( NaN == NaN ) // false    isNaN( ) 函数会帮我们确定这个参数是否 “不是数值”数值转换    Number()    parseFloat()    parseInt()    会自动从第0个开始寻找,如果遇到不是数值即停止寻找 返回已寻找的数值
String type
字符字面量    \n 换行    \r 回车    \b 退格字符串特点    ECMAScript 中的字符串一旦创建是不可能改变    可以用新的字符串 替换或填充    转换为字符串toString() 方法    数值/布尔值/对象和字符串都有 toString() 方法    null 和 undefined 没有 toString() 方法String() 转型函数    能将任何类型转换成 字符串 类型    如果有 String() 方法则调用该方法    如果值是 null,则返回 "null"    如果值是 undefined,则返回 "undefined"
Object type
var o = new Object()Object 的每个实例都具有下列属性和方法    constructor    hasOwnProperty    isPrototypeOf    propertyIsEnumberable    toLocaleString()    toString()    valueOf()

JS data type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.