javascript value types code example

Example 1: check data type in javascript

typeof("string"); //string
typeof(123); //number

Example 2: type javascirpt

console.log(typeof 42);

Example 3: javascript data types

/*JavaScript data types*/
//string
var string = 'ASCII text';
//int
var integer = 123456789;
//float
var float = 123.456;
//boolean, can be true or false
var t = true;
var f = false;
//undefined
var undef;//defaults to undefined
var undef = undefined;//not common, use null
//null
var nul = null;
//array
var arr = ['Hello','my','name','is','Dr.Hippo',123,null];
//object
var person = {'name':'John Smith','age':27};
//function
var fun = function(){
    return 42;
}

Example 4: javascript datatypes

dataTypes = {
    Numbers = 1,2,3, 100, 3.14
    Strings = 'Hello, World' "helloworld@gmail.com
    Boolean = true / false
    Null = 'Explicitly set a variable with no Value'
    Undefined = 'For variable that have not yet been defined'
    Object = 'Complex data structures - Arrays, Dates, Literals etc'
    Symbol = 'Used with objects' // usually not needed
}

Example 5: data types in javascript

1, 1.0 // Number
'String', "String"
true, false // Boolean
{id: 1;} // Object
[1, 2, 3] // Array

Tags: