Search the Blog

Wednesday, August 14, 2019

JavaScript datatypes syntax with demo code

typeof() - is the 'official' function that one uses to get the type in JavaScript, however in certain cases it might yield some unexpected results ...

1. Strings
typeof "String" or typeof Date(2011,01,01)

2. Number
typeof 42

3. Bool
typeof true (valid values true and false)

4. Object
typeof {} or
 typeof [] or
typeof null or
 typeof /aaa/ or
typeof Error()

5. Function
typeof function(){}

6. Undefined
var var1;
typeof var1


See also

Javascript Console opening in different browser
JavaScript Console methods and objects 
JavaScript Comments usage and sample example

JavaScript assertions debugging - console.assert()

Writes an error message to the console if the assertion is false. Otherwise, if the assertion is true, this does nothing.
console.assert('one' === 1)

Multiple arguments can be provided after the assertion–these can be strings or other objects–that will only be printed if the assertion is false:

console.assert does not throw an AssertionError (except in Node.js), meaning that this method is incompatible with most testing frameworks and that code execution will not break on a failed assertion.

See Also
JavaScript Object and XML interactively methods

JavaScript Object and XML interactively methods

console.dir(object) display an interactive list of the properties of the specified JS object.
The output is presented in a hierarchical listing with dis closure triangles that let you see the contents of child objects.

var myObject =
{    "foo":
             {        "bar":"Programming Logic and Code"    }
 };
console.dir(myObject);


var myObject = { 
                           "foo":{     
                                    "bar":"data" 
                                      }
                           };
console.dirxml(myObject);





console.log(document)
displays:

Translate