• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Is null the same as undefined ?

Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

In this snitppet the if is entered - but I do not understand why:

$.writeln (oFound + "   " + KLD_F.iError);
if (oFound == undefined || (KLD_F.iError != 0)) {  // Nothing found -----------
  KLD_F.DisplayInfoF (KLD_F.UItxt.ButtonFind.@msg_07.toString(), "red"); // not found (anymore)
  KLD_F.bNextCompOK = true;                     // propably look into next book component
} 

The writeln says:  null   0

Is in the condition null the same as undefined?

TOPICS
Scripting

Views

61

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Sep 05, 2022 Sep 05, 2022

HM, have found this in StackOverflow:

 

null === undefined // false
null == undefined // true

 

That means that my test is incorrect and I need to write it differently, probably:

 

if (oFound === undefined || (KLD_F.iError != 0)) {

 

But: In the script I often force this condition "not found" by setting the variable oFound to undefined ... Will ths still work?

Yes, this is the correct solution.

Edit

I have found an excellent explanation of the null vs undefined problem at StackOverflow. Look for

...

Votes

Translate

Translate
Community Expert ,
Sep 05, 2022 Sep 05, 2022

Copy link to clipboard

Copied

LATEST

HM, have found this in StackOverflow:

 

null === undefined // false
null == undefined // true

 

That means that my test is incorrect and I need to write it differently, probably:

 

if (oFound === undefined || (KLD_F.iError != 0)) {

 

But: In the script I often force this condition "not found" by setting the variable oFound to undefined ... Will ths still work?

Yes, this is the correct solution.

Edit

I have found an excellent explanation of the null vs undefined problem at StackOverflow. Look for "Please read the following carefully".

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines