1. Judge whether each other is equalfunction Btnclick () {alert (null = = NULL);//true alert (undefined==undefined);//true alert (Nan==nan);//false}Summarize:(1) Two null is equal(2) Two undefined are equal(3) Two Nan is unequalfunction Btnclick () {
Function demo () { alert (typeof a == "undefined");//true}function demo () { alert (a == null);//console error a is not defined}function demo (a) { alert (typeof a == "undefined");// True alert (A == null);//true}function demo () {
I believe many beginner JavaScript will have this idea: why JavaScript is null and undefined, relative to C, C + +, Java, they are all just null, why JavaScript is differentOne, historical reasons The web search learned that,when JavaScript was born
Introduction to null, undefined, and nullundefined in JavaScript
Null indicates a special value, which is often used to describe "null ". Perform the typeof operation on null, and the result returns the string "object". That is to say, null can be
You can just check if the variable have a truthy value or not. That meansif( value ) {}Would evaluate to true if are not value :
Null
Undefined
NaN
Empty string ("")
0
False
The above list represents all possible
JavaScript is such a weak type of language, in the judgment of equality is very troublesome, obviously not a thing, but equal. This example shows the equality of NULL, undefined, 0, false, and "". var arr = [null, undefined, 0, false, "];var str = ""
In JavaScript, we are often exposed to the 5 more special objects mentioned in the topic--false, 0, empty strings, null, and undefined. These objects are easy to use, so you have to be careful when you use them.Type detectionLet's come down and see
undefined is undefined, and the value is undefinedwhen the variable is not assigned a value. "Missing value", that is, there should be a value here, but there is no definition.underclared is a contaminated name, access to a variable that is not
False, zero, null, undefined, and empty string objects in Javascript
In Javascript, We often come into contact with the five special objects mentioned in the question -- false, 0, empty string, NullAnd undefined. These objects are easy to use
0. GreetingTurn over their own blog, the last one is June 26, said the update? Review just past this July, all day is the company's induction training plus their own small papers, every day to fight to 1 o'clock in the morning more, this is to hang
This article mainly introduces how to judge null, undefined, and NaN in JS. If you need it, you can refer to the following str = "s" ++;
Then Nan appears. Find it for a while.
The collected data is judged as follows:
1. Determine undefined:
The
In javascript, how does one determine whether a variable is null, undefined, Or NaN? Let's take a look at the specific judgment method.
It is mainly determined through the typeof method. typeof returns a string and has six possible results: "number",
Today, the main thing to learn is the data type aspect-the more learning more feel JS this language, really is amazing,very amazing, summed up under1. First to compare null with undefined:The NULL:JS keyword, which represents an object, but is empty.
Reproduced from:
Author: one pixel
Www.cnblogs.com/onepixel/p/7337248.html
In a recent book on "JavaScript Advanced Programming", which mentions the equality operator (= =), you cannot convert null and undefined to any other value until you compare
This article mainly introduces the method of determining null, undefined and nan in JS, and the friends who need it can refer to the following wrote a str = "s" ++; then appeared nan, looking for a while. Collect data as follows to Judge: 1.
wrote a str = "s" + +;
Then there was Nan, and for a while.
The information collected is as follows:
1. Judge undefined:
Copy Code code as follows:
var tmp = undefined;
if (typeof (tmp) = = "undefined") {
Alert ("undefined");
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->
Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
Html Xmlns
1. Null indicates an object that does not exist, and 0 when it is converted to a value. It means "no object", that is, it should not have a value and is commonly used to indicate that a function is attempting to return an object that does not exist.
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.