Thursday, May 11, 2017

Data types

function type(x) {
    console.log("typeof " + x + "=" + typeof x);
}
var n;
type(n);
var x = null;
type(x);
type(2);
type("2");
type("xyz");
type(true);
type({x: 1});
type(2.2);
type(["x", "y"]);
type(function(){});
type (new Boolean(true));
type(new Array(2,3));
type(new Number(2));
type(new Date());
type(new RegExp("[a-b]"));
type(new String("Hi"));
Output:
typeof undefined=undefined
typeof null=object
typeof 2=number
typeof 2=string
typeof xyz=string
typeof true=boolean
typeof [object Object]=object
typeof 2.2=number
typeof x,y=object
typeof function (){}=function
typeof true=object
typeof 2,3=object
typeof 2=object
typeof Fri May 12 2017 13:56:47 GMT+0530 (India Standard Time)=object
typeof /[a-b]/=object
typeof Hi=object

No comments:

Post a Comment