Typeof operator

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…

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

Thanx… i will use it

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

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

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!

1 Like

Thanx amanuel2, it was really helpful …

1 Like