javascript data type code example
Example 1: javascript data types
var string = 'ASCII text';
var integer = 123456789;
var float = 123.456;
var t = true;
var f = false;
var undef;
var undef = undefined;
var nul = null;
var arr = ['Hello','my','name','is','Dr.Hippo',123,null];
var person = {'name':'John Smith','age':27};
var fun = function(){
return 42;
}
Example 2: data types in javascript
var strSingle = 'John';
var strDouble = "Bob";
var num = 25;
var flo = 80.5;
var exp = 4.25e+6;
var isReading = true;
var isSleeping = false;
var undef;
var noValue = null;
var emptyObject = {};
var person = {"name": "Clark", "surname": "Kent", "age": "36"};
var car = {
model: "BMW X3",
color: "white",
doors: 5
}
var emptyArray = [];
var array = ["One", "Two"]
var func = function() {
alert("Code excuted");
}
var funcVar = function(amount) {
alert("Code excuted " + amount + " times");
}
typeof variable;
Example 3: js data types
string, number, boolean, null, undefined
Object, Function
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'
}
Example 5: data types in javascript
1, 1.0
'String', "String"
true, false
{id: 1;}
[1, 2, 3]