Get the App
SLTechnology News&Howtos  ›  Development  › 

How does javascript determine whether it is null or not

Shulou Source: shulou.com Published: 2022-06-02 01:35:12 09月29日 Update

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!

Tags: Variables functions contents situations characters data files blanks articles statements tabs spaces tabs learning help prompts codes parameters objects tutorials Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Docker NVidia Linux Microsoft