How to check if a variable is not null?

前端 未结 9 1084
太阳男子
太阳男子 2020-11-28 17:47

I know that below are the two ways in JavaScript to check whether a variable is not null, but I’m confused which is the best practice to use.

Should I d

9条回答
  •  被撕碎了的回忆
    2020-11-28 18:07

    Here is how you can test if a variable is not NULL:

    if (myVar !== null) {...}

    the block will be executed if myVar is not null.. it will be executed if myVar is undefined or false or 0 or NaN or anything else..

提交回复
热议问题