Theme images by Storman. Powered by Blogger.

Saturday 10 June 2017

Javascript interview questions: typeof

Question : what is typeof in javascript
Answer : The typeof operator returns a string indicating the type of the unevaluated operand.
Example : var a = 1;
               console.log(typeof a);// number

Question : Write the output
                console.log(typeof Infinity);
Answer : number

Question : Write the output
                 console.log(typeof null);
 Answer : 'object';

Question : Write the output
                 var a = [1 ,2 ,3];
                 console.log(typeof a);
 Answer : 'object';

Question : Write the output
                 console.log(typeof String('abc'));
 Answer : 'string';

Question : Write the output
                 console.log(new String('abc'));
 Answer : 'object';

Question : Write the output
                 typeof g;
 Answer : "undefined";

Question : Write the output
                 console.log(typeof NaN );
 Answer : "number";
* In ES6 use Number.isNaN() function for checking the value. Otherwise you can also use isNaN() .


2 on: " Javascript interview questions: typeof"