Что нового?
Интернет в Броварах
Карта Броваров
Спутниковая карта
Работа в Броварах
Как проверить в джаваскрипте определена ли переменная
Автор: Rage Noir - время 11:27 08/12/10

Second, no, they are not directly equivalent. If you really want to check for null, do:

if (null == yourvar) // with casting
if (null === yourvar) // without casting

If you want to check if a variable exist

if (typeof yourvar != 'undefined') // Any scope
if (window['varname'] != undefined) // Global scope
if (window['varname'] != void 0) // Old browsers

If you know the variable exists but don't know if there's any value stored in it:

if (undefined != yourvar)
if (void 0 != yourvar) // for older browsers

If you want to know if a member exists independent of whether it has been assigned a value or not:

if ('membername' in object) // With inheritance
if (object.hasOwnProperty('membername')) // Without inheritance

If you want to to know whether a variable autocasts to true:


От сюда

Добавить коммент



Комментарии пользователей

emmWdT84m004:59 29/05/16

Eceoomins are in dire straits, but I can count on this!