Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does javascript determine whether it is null or not

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 "javascript how to judge whether null value", the content is easy to understand, clear, hope to help you solve doubts, the following let the editor lead you to study and learn "javascript how to judge whether null value" this article.

Methods: 1. Use the statement "if (variable = = null | | variable =" | variable = = undefined) {judged to be empty code} "to judge the situation of null, null and undefined; 2, replace the blank character with" variable .replace (/\ sUnig, "") "and determine whether it is empty or not.

The operating environment of this tutorial: windows10 system, javascript1.8.5 version, Dell G3 computer.

How does javascript determine whether it is null or not

In js, empty situations include spaces, white space characters, null, undefined, empty arrays, empty objects, tabs, etc., so you need to judge whether the data is empty or not.

Create a new html file, named test.html, to explain how js determines whether it is empty or not. In the test.html file, use function to declare a function, str is the parameter of the function, in the is_e () function, first use the if statement to judge the situation of null, null, and undefined, and if it conforms, the prompt of "content is empty" pops up.

Within the is_e () function, use regular expressions to replace white space characters, spaces, tabs, page feeds, and so on with blanks.

Then use the if statement to determine whether the data processed in the previous step is empty, and if so, the prompt "content is empty" pops up.

Outside the is_e function, define a variable str to hold the data you want to judge. For example, here you set the str variable to an empty character and use the is_e () function to judge.

Open the test.html file in the browser and view the result of the judgment variable.

The above is all the contents of the article "how to determine whether the javascript is null or not". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, 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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report