Skip to main content
K.Daube
Community Expert
Community Expert
September 5, 2022
Answered

Is null the same as undefined ?

  • September 5, 2022
  • 1 reply
  • 179 views

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?

This topic has been closed for replies.
Correct answer K.Daube

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".

1 reply

K.Daube
Community Expert
K.DaubeCommunity ExpertAuthorCorrect answer
Community Expert
September 5, 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 "Please read the following carefully".