Программирование > JavaScript & JScript

Как определить необъявленную переменную в JS?

(1/1)

Vladn:
Такая проблема: в JavaScript нужно узнать, была ли обьявлена определенная переменная. В "MSDN Library - July 2000" есть рецепт:


--- Цитировать ---If a variable has not been declared, you cannot compare it to undefined, but you can compare the type of the variable to the string "undefined"

The undefined property is useful when explicitly testing or setting a variable to undefined.

Example
var declared;                         //Declare variable.
if (declared == undefined)            //Test variable.
  document.write("declared has not been given a value.");

if (typeOf(notDeclared) == "undefined")
  document.write("notDeclared has not been defined.");
Requirements
Version 5.5

--- Конец цитаты ---



Запускаю следующий хтмл:


--- Код: ---

if (typeOf(notDeclared) == "undefined")
  document.write("notDeclared has not been defined.");


--- Конец кода ---


Результат - нулевой. Заменял на - ничего. IE6.x. Помогите разобраться.

Макс:
может typeof() ?

Навигация

[0] Главная страница сообщений

Sitemap 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 
Перейти к полной версии