xxxxxxxxxx
Number // var age = 18
String // var name = "codepadding"
Boolean // var prgramming = true
Object // var fullName = {first:"Code", last:"Padding"};
Undefined // var program; typeof program
array // var language = ["javaScaript","dart"]
null // var error = null
xxxxxxxxxx
var age = 18; // number
var name = "Jane"; // string
var name = {first:"Jane", last:"Doe"}; // object
var truth = false; // boolean
var sheets = ["HTML","CSS","JS"]; // array
var a; typeof a; // undefined
var a = null; // value null
xxxxxxxxxx
true, false // 1. Boolean
null // 2. Null
undefined // 3. Undefined
1, 4, 7, 231, 51, 11, 9 // 4. Number
9007199254740991n // 5. BigInt
'Hello', 'World', 'Uzbekistan' // 6. String
let sym1 = Symbol() // 7. Symbol
{a: 123}, [1] // 8. Objects
xxxxxxxxxx
//String Data Type
var strSingle = 'John'; //String with single quotes
var strDouble = "Bob"; //String with double quotes
//Number Data Type
var num = 25; //Integer
var flo = 80.5; //Floating-point number
var exp = 4.25e+6; //Exponential notation, this equates to 4250000
//Boolean Data Type
var isReading = true; //Yes, I'm reading
var isSleeping = false; //No, I'm not sleeping
//Undefined Data Type
var undef; //If a value is never assigned, any output will be 'undefined'
//Null Data Type
var noValue = null; //Null meaning that it is has no value, not the same as 0 or ""
//Object Data Type
var emptyObject = {};
var person = {"name": "Clark", "surname": "Kent", "age": "36"}; //The quotes around the propety name can be omitted if the property name is a valid JS name
var car = { //Same as person but easier to read
model: "BMW X3", //Example with quotes around property name ommitted
color: "white",
doors: 5
}
//Array Data Type
var emptyArray = []; //An array can be of any data types (string, number, boolean, etc.)
var array = ["One", "Two"] //String array, note the index of the first element is 0
//Function Data Type
var func = function() { //Calling the function: func();
alert("Code excuted"); //Outputs: Code executed
}
var funcVar = function(amount) { //Calling the function: funcVar(6);
alert("Code excuted " + amount + " times"); //Outputs: Code executed 6 times (if input was 6)
}
//Typeof Operator
typeof variable; //Returns the data type of the variable
xxxxxxxxxx
/*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;
}
xxxxxxxxxx
// What are JavaScript Data Types?
JavaScript has 7 Datatypes
1. String
2. Number
3. Boolean
4. Undefined
5. Null
6. Symbol
7. Object
let name = "Chetan"; // string
let age = 30; // number
let fullName = {first:"Chetan", last:"Nada"}; // object
let truth = false; // boolean
let language = ["HTML","CSS","JS"]; // array
let x; typeof x; // undefined
let val = null; // value null
const value1 = Symbol('hello');
const value2 = Symbol('hello');
console.log(value1 === value2); // false because Symbols are immutable (cannot be changed) and are unique.
xxxxxxxxxx
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
}
xxxxxxxxxx
/*
Data Types Intro
- String
- Number
- Array => Object
- Object
- Boolean
*/
console.log("Osama Mohamed");
console.log(typeof "Osama Mohamed");
console.log(typeof 5000);
console.log(typeof 5000.99);
console.log(typeof [10, 15, 17]);
console.log(typeof { name: "Osama", age: 17, country: "Eg" });
console.log(typeof true);
console.log(typeof false);
console.log(typeof undefined);
console.log(typeof null);
xxxxxxxxxx
var age = 18; // number
var name = "Jane"; // string
var name = {first:"Jane", last:"Doe"}; // object
var truth = false; // boolean
var sheets = ["HTML","CSS","JS"]; // array
var a; typeof a; // undefined
var a = null; // value null