In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces what the original data types in es6 have related knowledge, the content is detailed and easy to understand, the operation is simple and fast, and has a certain reference value, I believe you will gain after reading the original data types in this es6, let's take a look at it.
There are six primitive data types: 1, Null type, indicating an "empty" value, that is, no value; 2, Undefined type, indicating undefined; 3, Number type, representing numbers (integers, floating numbers, etc.); 4, String type, a piece of text wrapped in single or double quotation marks; 5, Symbol type, etc.
The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.
There are nine data types in es6, which can be divided into two categories:
Raw data types (6): string (String), number (Number), Boolean (Boolean), empty (Null), undefined (Undefined), Symbol
Reference data types (3): object (Object), array (Array), function (Function).
Let's talk about six raw data types.
The data type describes the null null value, which represents the undefined value of the non-object undefined, the initialization value number number that is not assigned, the value string string of the mathematical operation, the boolean Boolean value of the information flow, and the logical operation value Symbol that represents the unique value.
1. Null type
Null is a special data type with only one value, indicating a "null" value, that is, there is no value, nothing, and is used to define a null object pointer.
Using the typeof operator to view the type of Null, you will find that the type of Null is Object
Var a = null;console.log (typeof a)
Indicates that Null actually uses a special value that belongs to Object (object). So by assigning the variable to Null, we can create an empty object.
2. Undefined type
Undefined is also a special data type with only one value, indicating that it is undefined. When we declare a variable without assigning a value to it, the default value for that variable is Undefined. For example:
Var num;console.log (num); / / output undefined
When you use the typeof operator to look at unassigned variable types, you will find that they are also of type undefined. If you look at the type of an undeclared variable using the typeof operator, you will find that the undeclared variable is also undefined. The sample code is as follows:
Var message;console.log (typeof message); / / output undefinedconsole.log (typeof str); / / output undefined
Description: similarities and differences between null and undefined:
What they have in common: both are data types of the same value; both return false; when they participate in the judgment. Neither has a method.
Differences:
(a) null is an object, but undefined is not an object
(B) null is a keyword, undefined is not a keyword
(C), null is 0 when converted to a number, and undefined is NaN when converted to a number
(d), typeof null returns' object',typeof undefined returns' undefined'
Alert (null = = undefined); / / true
3. Number type
Numeric (Number) types are used to define numeric values. Integer and decimal numbers (floating point numbers) are not distinguished in JavaScript, and are uniformly represented by Number type, as shown in the following example:
Var num1 = 123; / / integer var num2 = 3.14; / / floating point number
Note: the values that can be defined by the Number type are not infinite, and the Number type in JavaScript can only represent values between-(253-1) and (253-1).
Some very large or very small numbers can also be expressed by scientific (exponential) counting, as shown in the following example:
Var yearly 123e5; / / 123x 10 to the fifth power, that is, 12300000var zonal 123emur5; / / 123x 10 to the-5th power, that is, 0.00123
In addition, there are some special values in the Number type, which are Infinity,-Infinity, and NaN, where
Infinity: a number used to represent positive infinity, usually a number greater than 1.7976931348623157e+308
-Infinity: used to represent a negative infinity, usually a number less than 5e-324
NaN: non-numeric (abbreviation for Not a Number), used to represent invalid or undefined mathematical operations, such as 0 divided by 0.
Tip: if the result of a calculation is out of the range of Number type in JavaScript, the number will be automatically converted to infinity, with positive number Infinity and negative number-Infinity.
There is a strange work in number, which is not equal in itself. That is alert (NaN = = NaN) / / false
But NaN is a data type, which means that the return value of typeof NaN is' number'
For the above two features, ECMAScript provides a function isNaN (); the purpose is to determine whether the incoming value can be converted to a number, and the return value is a Boolean value.
The conversion of an empty string to a number is 0
You can use Number () to convert a value to a numeric type
4. String type
A string (String) type is a piece of text wrapped in single or double quotes, such as' 123', "abc". It is important to note that single and double quotes are different ways to define a string and are not part of a string.
When defining a string, if the string contains quotation marks, you can use the backslash\ to escape the quotation marks in the string, or select a different quote from the string to define the string, as shown in the following example:
Var str = "Let's have a cup of coffee."; / A double quotation mark contains single quotation marks var str ='He said "Hello" and left.'; / / single quotation marks contain double quotation marks var str ='We\'ll never give up.'; / / escape single quotation marks in a string using a backslash
5. Boolean type
The Boolean type has only two values, true (true) or false (false), which are often used in condition judgment. In addition to directly using true or false to define Boolean variables, you can also get Boolean values through some expressions, such as:
Var a = true; / / define a Boolean value truevar b = false; / / define a Boolean value falsevar c = 2 > 1; / / expression 2 > 1 holds, the result is "true (true)", so the value of c is truevar d = 2 < 1 of Boolean type; / / expression 2 < 1 is not true, the result is "false", so the value of c is false of Boolean type
The boolean type is mainly used to determine
Normally, only these six cases will be converted to false: empty string, null, undefined, 0,-0, NaN
There are two ways to convert an array to a Boolean value: Boolean (),! ()
6. Symbol type
Symbol is a new data type introduced in ECMAScript6, which represents a unique value. Values of type Symbol need to be generated using the Symbol () function, as shown in the following example:
Var str = "123"; var sym1 = Symbol (str); var sym2 = Symbol (str); console.log (sym1); / / output Symbol (123) console.log (sym2); / / output Symbol (123) console.log (sym1 = = sym2) / / output false: although sym1 and sym2 look the same, they are actually not the same. According to the characteristics of the Symbol type, sym1 and sym2 are both unique. This is the end of the article on "what are the original data types in es6?" Thank you for reading! I believe you all have a certain understanding of the knowledge of "what are the original data types in es6". If you want to learn more, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.