In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how es6 judges whether the value is empty". Xiaobian shows you the operation process through actual cases. The operation method is simple, fast and practical. I hope this article "how es6 judges whether the value is empty" can help you solve the problem.
Judgment method: 1. Use the "typeof(variable)=='undefined'" statement, if it returns "true", it is empty;2. Use the typeof statement to judge whether the value type is "null", if it is, it is empty;3. Use the "! Variable && Variable!= 0"statement, null if the return value is"true."
Operating environment of this tutorial: Windows 7 system, ECMAScript version 6, Dell G3 computer.
In development we often have to make non-null judgments, and JavaScript has two special data types: undefined and null:
null: Null type, meaning "null value", represents a null object pointer, using the typeof operation to get "object", so we can think of it as a special object value.
undefined: Undefined type, when a variable is declared uninitialized, the result is undefined.
Let's see how es6 determines whether the value is null (non-null).
1, only determine whether undefined
var a; var b = null; if(typeof(a) == 'undefined'){ console.log('a is undefined ');}else{ console.log('a is undefined');} if(typeof(b) == 'undefined'){ console.log('b is undefined ');}else{ console. log ('b is undefined');}
2, only determine whether it is null
var a;var b = null; if(! a && typeof(a) !== 'undefined' && a != 0){ console.log ('a isn');}else{ console.log ('a isn');} if(! b && typeof(b) !== 'undefined' && b != 0){ console.log ('b is null');}else{ console.log ('b is not null');}
3, non-empty judgment
(1) In actual development, we may not need to distinguish so carefully, but simply make a non-null judgment (if the variable is undefined or null means null), then we can use the following method:
var a;var b = null; if(! a) { console.log ('a is null');}else{ console.log ('a is not null');} if(! b) { console.log ('b is null');}else{ console.log ('b is not null');}
(2) If the variable is likely to be the number 0, the above judgment is not rigorous enough, and the following method can be used:
var a;var b = null;var c = 0; if(! a && a != 0){ console.log ('a is null');}else{ console.log ('a is not null');} if(! b && b != 0){ console.log ('b is null');}else{ console.log ('b is not null');} if(! c && c != 0){ console.log ('c is null');}else{ console.log ('c is not null');}
About "es6 how to determine whether the value is empty" content introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the industry information channel. Xiaobian will update different knowledge points for you every day.
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.