JavaScript directive

Is there a JavaScript directive like preprocessor directives in C and C++ to test whether a variable is defined or not? I need the compile time directive (i.e. while processing the JavaScript)
Thanx in advance.
[219 byte] By [miteshpandey] at [2007-11-20 1:48:59]
# 1 Re: JavaScript directive
Nope. I don't know of any programming language that actually defines variables. They are easily converted from one type to another though.

Depending on what you are attempting to accomplish you might be able to use some top-level functions (http://www.w3schools.com/jsref/jsref_obj_global.asp) such as isNaN() or isFinite().
PeejAvery at 2007-11-8 0:41:09 >
# 2 Re: JavaScript directive
Nope. I don't know of any programming language that actually defines variables.

I don't understand this statement. Could you explain?

As I understand VB is an interpreted language. May be same goes with VBScript and JavaScript which I think do not go through the preprocessor like C and C++ go through.

I need something like "#ifdefined" or "#ifndef"

Let me try to explain my problem a bit.

I have an entity called "Name"

This entity could be defined out of javascript. If it is defined out of javascript I do not need to define it in my javascript. But if it is not defined outside I need to define it in my javascript. Something along the line:

if(!Name)
{
var Name = "foo";
}

However this doesn't work

I also tried the following:

if(Name == undefined)
{
var Name = "foo";
}

This too doesn't work
miteshpandey at 2007-11-8 0:42:10 >
# 3 Re: JavaScript directive
No. There is no way to tell if a variable has been defined in JavaScript.

I thought you were talking about the variable type.
PeejAvery at 2007-11-8 0:43:11 >
# 4 Re: JavaScript directive
what a tough question.
can u tell clearly to me an example of the case when will a variable have been declared outside of the javascript.
or do u mean..
if there are a variable XXX has been declared in VBSCRIPT... then in the same page, u want to use the same variable XXX in javascript, but firstly u want to chek whether it has been declared before ... ?
szpilman at 2007-11-8 0:44:11 >
# 5 Re: JavaScript directive
szpilman, This question has already been answered and is in fact very simple.

He was simply asking if you can tell if a JavaScript variable had been created yet or not.
PeejAvery at 2007-11-8 0:45:13 >
# 6 Re: JavaScript directive
I am actually not using JavaScript but a customized JavaScript which is called ESP specifically developed by the Company whose software I use. ESP works much more like JavaScript.

My ESP page interfaces with the php page.

If the ESP page is called through the php page everything is OK but when ESP page is directly called the particular php page variable is is reported as undefined variable.

I needed a mechanism to detected if the particular variable is defined or not.

The variable will be defined if called through php page but not when called directly.

I have the solution to the problem:

I use the following code which might relate to JavaScript but maybe only to ESP

<%

if(global.Name = undefined)
{
var Name = "";
}

%>

Don't know if global is ESP specific or it belongs to JavaScript.
miteshpandey at 2007-11-8 0:46:10 >
# 7 Re: JavaScript directive
Don't know if global is ESP specific or it belongs to JavaScript.
As I have stated before, you are not using ESP. ESP is not a programming language. You are using ASP ( http://www.google.com/search?hl=en&q=asp&btnG=Google+Search).

Global belongs to ASP, not JavaScript.
PeejAvery at 2007-11-8 0:47:08 >
# 8 Re: JavaScript directive
By me I am actually not using JavaScript but a customized JavaScript which is called ESP specifically developed by the Company whose software I use. ESP works much more like JavaScript.

I have already stated this that this ESP I am talking about is not widely used but is specific to "Mbedthis" whose web server I am using.

Here is a link to its documentation on variables;

global (http://www.mbedthis.com/products/appWeb/doc/common/ejs/standard.html)
miteshpandey at 2007-11-8 0:48:09 >
# 9 Re: JavaScript directive
Ah. That would be why I have never heard of it. It isn't really big at all. ESP ( http://www.mbedthis.com/products/appWeb/doc/common/esp/overview.html) was recently created and isn't widely known. Interesting stuff.
PeejAvery at 2007-11-8 0:49:07 >