top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

In JavaScript how to check if a variable is null/undefined?

+1 vote
476 views
In JavaScript how to check if a variable is null/undefined?
posted Aug 4, 2014 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

In Javascript you can check by using typeof for undefined variables

Example:

if(typeof(variable) == 'undefined')
    {
        alert("Variable is undefined");
    }
if(variable == null) 
   {
       alert("Variable is null");
   }
answer Aug 8, 2014 by Manish Tiwari
Similar Questions
0 votes

I have a variable created by some rails in my controller that looks like this:

@myvar= row["myvar"]

and I want to pass it into some javascript that is referenced from within my view:

view:

js (play_time):

I am trying to pass " into the js [obviously that is not the right syntax]. Can anyone help?

+2 votes

Is there any way so that i will get to know about my variable is a number or not without using Javascript?

...