Typeof operator

javascript

#1

out of course, but this thing is not working in my browser, i want to alert a "NUMBER".


var num = 78;
if(num == typeof Number){
alert("NUMBER");
}
else{
alert("NOT A NUMBER");
};


|_______________________________________________________|

var num = 78;
if(typeof num == "Number"){
alert("NUMBER");
}
else{
alert("NOT A NUMBER");
};

NONE OF THEM IS WORKING, PLEASE HELP URGENTLY...


#2

first of, to use the typeof operator:

typeof(num);

you are using it incorrectly, plus this function only returns the type. You are not comparing the returned type with anything, and if i where you i would just use the isInteger build in function


#3

Thanx... i will use it


#4

please use the link i provided, it will show you how to use isInteger


#5

I m learning javascript with professional javascript for web developers by nicholas c zakas


#6

Basically Number.isInteger gives you true or false @pyninja98069 ..

var num= 32434234;
console.log(Number.isInteger(num));//Going to log true to console..

And typeof gives you basically the actual type of the variable For example

var str = "BLAHBLAHBLAH"
console.log(typeof(str)); //Going to log String to the console..

Hope you understand how to use this, and what it is!


#7

Thanx amanuel2, it was really helpful ....