GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   Javascript: How do I check if a var is null or hasn't been set?? (https://gfy.com/showthread.php?t=549497)

Zester 12-08-2005 03:02 AM

Javascript: How do I check if a var is null or hasn't been set??
 
sounds simple doesn't it? this is fucking driving crazy

lets say "myvar" was never mentioned in the code anywhere.
the following gives an error message "myvar is undefined" which I want to avoid:

Code:

if ( myvar = =  undefined )
{
  // do nothing
}

I also tried:
Code:

if ( myvar = =  null )
if ( myvar = =  0 )
if ( myvar = =  "" )
if ( myvar = =  '' )

of course I don't use spaces between the two "=" but that's just for displaying

J.P. 12-08-2005 03:53 AM

try this:
Code:

if (typeof myvar = = "undefined") {
  // do something - or nothing :)
}

this should solve your problem...

of course, drop the space between = and = :)

emthree 12-08-2005 06:09 AM

You must nul your var

Zester 12-08-2005 09:55 AM

Quote:

Originally Posted by J.P.
try this:
Code:

if (typeof myvar = = "undefined") {
  // do something - or nothing :)
}

this should solve your problem...

of course, drop the space between = and = :)

thanks mate


All times are GMT -7. The time now is 04:19 PM.

Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123