js basic data types code example

Example 1: 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 2: js data types

//There are 7 data types in JS 
//They're split in two categories - (Primitives and Complex Types)

//Primives
string, number, boolean, null, undefined

//Complex types
Object, Function

Example 3: 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 4: data types in javascript

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