A summary of "basic types" in JavaScript _javascript skills

Source: Internet
Author: User

One of the most frequently asked questions in a front-end interview is "What are some of the basic types of javascript?" ”。

Some answer "number, String, Boolean", some may add "Null, Undefined". And one might think that "object" is also a basic type. What exactly is it like?

The concept of the so-called "basic type (primitive types)" ECMAScript (V3,V5) is not at all, it only divides the type into 6 kinds.

ECMAScript only refers to the type, with types, in v3,v5 the whole document search keyword "Primitive" also did not see "primitive type", "primitive value" there are, such as true/false/0-9. This shows that there is no such thing as "basic type" or "Primitive type" (primitive types). There are 6 basic types if you have to say there is an object that is obviously the case.

Some books often use this concept, such as the first, second, and third editions of JavaScript advanced programming.

The first edition mentions 5 original types, namely undefined, Null, Boolean, number, String

The second and third editions have also produced a simple data type, translated as a primitive datatype (also known as a basic data type), and called an object as a complex data type.

Another classic book, "The JavaScript Authority Guide (6th Edition)" Chapter 3rd also mentions primitive types

First, the basic types (primitive types) and object types, the basic types are divided into numbers, strings, Boolean, and two special null,undefined.

5 years ago, there are few JavaScript books, these two books is the second, the impact is very large, is a classic. Therefore, there are few jser affected by this. I think the book author divides language types into basic types (meta types) and object types (complex types) is also logical, and complex types are composed of simple types. Also affected by other languages such as Java, they also divide types into basic types (8 types) and object types.

But there is no such thing as a primitive types in ECMAScript, just as it has no concept of Class (class) (people with other languages still like to use noun "classes" in JavaScript). It refers to the type, it can be understood as a basic type, but also should be 6 kinds. The basic type here is also not a basic type in Java because it contains complex data types-objects.

Not all books believe that there are only 5 basic types of JavaScript (excluding objects), and that the essence of JavaScript and programming practices is 6, as follows

It does not classify null as one, but it increases the function type. Oh, there are all sorts of answers, and next time someone asks the question how to answer it?

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.