In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "what are the basic data types of ecmascript", the content is simple and easy to understand, and the organization is clear. I hope it can help you solve your doubts. Let Xiaobian lead you to study and learn this article "what are the basic data types of ecmascript".
There are five basic data types of ecmascript: 1. Undefined type, which means undefined;2. Null type, which means a "null" value, that is, there is no value, which is often used to define a null object pointer;3. Number type;4. String type;5. Boolean type.
Operating environment for this tutorial: Windows 7, ECMAScript version 5, Dell G3 PC.
ECMAScript has five basic data types: Undefined, Null, Number, String, Boolean, and a complex data type, Object (consisting of unordered name-value pairs).
A few data types that are not clearly distinguished are summarized as follows:
1. Determine the data type of a variable by typeOf operator
"undefined"---if the value is undefined;
"boolean"--if the value is boolean;
"string"--if the value is a string;
"number"--if the value is numeric;
"object"--if the value is an object or null;
"function"--if the value is a function;
Example:
var message = "some string";alert(typeOf message); //"string"alert(typeOf(message)); //"string"alert(typeOf 95); //"number"
Undefined type (value undefined)
var variable declared but not initialized is undefined.
Example:
var message;alert(message == undefined) ; //true
Null type (null value)
A null value represents a null object pointer.
Example:
var obj = null;alert(typeOf obj); //"object"
4. Number type
This type of value is relatively large, focusing on NaN. NaN represents the case where an operand that was supposed to return a value does not return a value, i.e., any number divided by a non-number in ECMAScript returns NaN. NaN has two characteristics: first, any operation involving NaN will return NaN; second, NaN is not equal to any value, including NaN itself.
Example:
alert(NaN == NaN); //false
isNaN() function, this function takes a parameter, this parameter can be any type, through isNaN() function can determine whether this parameter is "not a number", this function receives a value, it will try to convert it to a number, any value that cannot be converted to a number will cause this function to return true.
Example:
alert(isNaN(NaN)) ; //truealert(isNaN(10)); // falsealert(isNaN("10")); //falsealert(isNaN("blue"));//true (cannot be converted to numeric type) alert(isNaN(true)); // false (true can be converted to 1)
5. String type
String type is a piece of text enclosed in single quotes '' or double quotes "", for example '123',"abc". Note that single quotes and double quotes are different ways of defining a string and are not part of it.
When defining a string, if the string contains quotation marks, you can escape quotation marks in the string using the backslash\, or choose quotation marks different from those in the string to define the string, as shown in the following example:
var str = "Let's have a cup of coffee. "; //double quotes contain single quotes var str ='He said "Hello" and left. '; var str = 'We\'ll never give up. '; //use backslashes to escape single quotes in strings
6. Boolean type
Boolean type has only two values, true (true) or false (false), which are used more when making conditional judgments. In addition to directly using true or false to define variables of Boolean type, you can also obtain Boolean values through some expressions, such as:
var a = true; //define a Boolean truevar b = false; //define a Boolean falsevar c = 2 > 1; //expression 2 > 1 holds, the result is "true", so the value of c is truevar d = 2 < 1 of Boolean type;//Expression 2 < 1 does not hold, the result is "false", so the value of c is Boolean false. Above is "What are the basic data types of ecmascript". All the contents of this article, thank you for reading! I believe that everyone has a certain understanding, hope to share the content to help everyone, if you still want to learn more knowledge, welcome to pay attention to 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.