| Refresh | Home EGTry.com

primitive data type and constants


commentsJavascript sourceExecution result in your current browser
all integer or floating numbers are same, they represented as 64-bit floating point numbers
  var int1=15;
  var hex1=0xF;
  var long1=15;
  var float1=15.0;
  document.write("int1  typeof="+typeof(int1)+" value="+int1);
  document.write("<br/>hex1  typeof="+typeof(hex1)+" value="+hex1);
  document.write("<br/>long1  typeof="+typeof(long1)+" value="+long1);
  document.write("<br/>float1 typeof="+typeof(float1)+" value="+float1);
  document.write("<br/>int1===hex1?  "+(int1===hex1));
  document.write("<br/>hex1===long1? "+(hex1===long1));
  document.write("<br/>float1===long1? "+(long1===float1));

nubmer constants
   var constants=["Number.MAX_VALUE", "Number.MIN_VALUE", 
    "Infinity", 
    "Number.POSITIVE_INFINITY", "Number.NEGATIVE_INFINITY",
    "NaN", "Number.NaN"
   ];
   for (var i=0; i<constants.length; i++) {
     var name=constants[i];
     document.write(
     "<br/>"+name+"= "+eval(name)
     );
   }
   

String and Char are all "string"
     var StringExamples=["Hello", 'Hello', 
    "'Are you ok', he said.", '"I am ok"', 
    "", "Line1\nLine1", ''
     
     ];
   for (var i=0; i<StringExamples.length; i++) {
     var stringValue=StringExamples[i];
     document.write(
     "<br/>"+stringValue
     );
   }
   
   document.write( ("Hello" === 'Hello'));

boolean
    var b1=1 === 1;
    var true1=true; //True or TRUE are not valid constant
    
    var false1=false;
    
    document.write(typeof(b1)+" "+b1);
    document.write("<br/>  constant true="+typeof(true1)+" "+true1);
    document.write("<br/>  constant false="+typeof(false1)+" "+false1);
    document.write("<br/> true===b1?"+(true1===b1));

undefined is not a keyword and is a global variable
     var b;
     document.write(
     "uninitialized variable: typeof="+typeof(b)+", value="+b);
     document.write("<br/>compare with two undefined variable: "+ (undefined===b)); //test if a variable is ever initialized

null is the language keyword and it is a special object
     document.write("null typeof is: "+typeof(null));
     document.write("<br/>the value of null: "+null);