In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/01 Report--
This article mainly explains "jquery how to judge whether it is a floating point number". The explanation in the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "jquery how to judge whether it is a floating point number".
Basic data types in JS (ES6): 1. Numerical (Number): including integers, floating point numbers, 2. Boolean (Boolean), 3. String type (String), 4. Array (Array), 5. Null value (Null), 6. Undefined (Undefined), the basic data type is accessed by value because you can directly manipulate the actual value stored in the variable.
Reference types: Object, Array, Function, Data. Reference data types are objects stored in heap memory
1.typeof
Var a
Console.log ("1:" + typeof a)
Var b=null
Console.log ("2:" + typeof b)
Var c=undefined
Console.log ("3:" + typeof c)
Var d=new Object
Console.log ("4:" + typeof d)
Var e=function () {}
Console.log ("5:" + typeof e)
Var f = {}
Console.log ("6:" + typeof f)
Var gathers'
Console.log ("7:" + typeof g)
Var h = []
Console.log ("8:" + typeof h)
Var i=true
Console.log ("9:" + typeof I)
Var jung123
Console.log ("10:" + typeof j)
Var k=NaN
Console.log ("11:" + typeof k)
Var lenses / ^ [- +]?\ dflowers /
Console.log ("12:" + typeof l)
The print result is as follows
Summary: typeof is object for null, undefined, NaN, array, regular, and Object.
2.constructor
Constructor is used to determine the prototype of a variable, and the constructor property returns a reference to the array function that created the object.
When a function F is defined, the JS engine adds a prototype prototype to F, then adds a constructor attribute to prototype and points to a reference to F. when var f=new F () is executed, F is treated as a constructor, f is an instance object of F, and the constructor on F prototype is passed to f, so f.constructor===F
Var F=function () {}
Console.log (F.prototype)
Var f=new F ()
Console.log (f.constructor===F) / / true
It is not difficult to see that F uses the constructor on the prototype object to reference itself. When F is used as a constructor to create an object, the constructor on the prototype is inherited to the newly created object. From the perspective of prototype chain, the constructor F is the type of the new object. The point of this is to make the new object have a traceable data type after it is born, that is, the object's constructor property points to its constructor.
So built-in objects are built internally to make this judgment.
Note:
Null and undefined are invalid objects, so there will be no constructor. These two types of data need to be judged in other ways.
The constructor attribute does not necessarily point to the constructor, it can also be modified and changed (when F.prototype = {} is rewritten, constructor will be overwritten by default)
Instanceof
The instanceof operator is used to test whether an object has a prototype property of a constructor in its prototype chain.
And constructors have these basic types: String, Number, Boolean, Undefined, Null, Symbol (ES6 introduces a new primitive data type, Symbol, which represents a unique value)
Complex type: Array,Object
Other types: Function, RegExp, Date.
Var obj=new Object ()
Obj instanceof Object / / true
Note that the object (object) must be on the left. If not, return false directly, as shown in:
Var num=1
Num instanceof Number / / false
Num=new Number (1)
Num instanceof Number / / true
You can see that they are all num, and they are all 1, but because the first one is not an object, it is a basic type, so it returns false directly, while the second one is encapsulated into an object, so true.
We should pay close attention to this problem here. Some say that the _ _ proto__ of the detection target is the same as the prototype of the constructor, that is, true is returned. This is not rigorous. It must be detected only if the object is detected, such as:
Basic type
Var num=1
Num.__proto__===Number.prototype / / true
Num instanceof Number / / false
Num=new Number (1)
Num.__proto__===Number.prototype / / true
Num instanceof Number / / true
Num.__proto__=== (new Number (1)). _ _ proto__ / / true
As can be seen from the above example, 1 is almost the same as new Number (1), except that the difference lies in whether it is encapsulated into an object, so the result of instanceof is different, string, boolean, etc., these basic types are the same.
New String (1) / / String
String (1) / / "1"
New String (1) is different from String (1). New is encapsulated as an object, while what does not have new is just a basic type conversion, or a basic type.
Other basic types are the same.
Complex types, such as arrays and objects, and even functions, are different from basic types.
Complex type
Var arr= []
Arr instanceof Array / / true
Arr instanceof Object / / true
Array.isArray (arr) / / true
Complex types generate constructors directly from literals, so they don't have the same two cases as basic types.
But the above problem, of course, is that the basic type also has this problem, which is compared with Object. No way. Object is at the top of the prototype chain, so it returns true, as follows:
(new Number (1)) instanceof Object / / true
Since from the bottom up, for example, if you judge that it is Number, there is no need to judge whether it is Object or not, because it is already Number.
Thank you for your reading, the above is the content of "how to judge whether jquery is a floating point number". After the study of this article, I believe you have a deeper understanding of how to judge whether jquery is a floating point number. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
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.