JavaScript Learning notes-data types

Source: Internet
Author: User
Tags object object

1. Data type

JS data type Total 6 kinds

respectively:

Numeric, String, Boolean, Undefind,null, object the most basic data types are 3 kinds: numeric, String, and Boolean objects can be divided into 3 subtypes: narrow objects, arrays, functionsnarrow arrays and objects are two different ways of combining data. And the function is actually the method of processing the data. JS treats functions as a data type that can be assigned and passed like other types of data2. Data type judging three methods of judging
> typeof> instanceof> Object.ptototype.toString ()

Experimental data and return values

typeof 123 "number" typeof ' 123 ' "string" typeof false "Boolean" function f () {}typeof F "function" typeof  undefined " Undefined "typeof v" undefined "typeof Window" Object "typeof {}" Object "typeof []" object "typeof Null" Object "var arr = []; Console.log (Object.prototype.toString.call (arr))  vm1072:2 [Object array]var arr = {};console.log ( Object.prototype.toString.call (arr))  Vm1075:2 [Object Object]

3.null and undefinded

nullAnd undefined both can say "no", meaning very similar

The distinction between null and Undefindednull is an object that represents none, and a value of 0;undefined is a primitive value that represents none, and a value of NaN4 when converted to a number. Boolean conversion rule: except for the following six values are converted to false, other values are considered true
Undefinednullfalse0nan "" or "(empty string)

[]the Boolean value corresponding to the empty array () and the empty object ( {} ) aretrue

if ({}) {Console.log (' empty object is true ');} Vm1115:2 Empty object is Trueif ([]) {Console.log (' empty array is true ');} Vm1118:2 empty Array is true

This blog post learns from Nanyi's JavaScript standard reference tutorial (Alpha)

JavaScript Learning notes-data types

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.