JS DATA TYPES
PRIMITIVE IMMUTABLE
NON PRIMITIVE MUTABLE
COMPOSITE COMBINATION OF PRIMITIVE & OTHER DATA TYPES
TRIVIAL PRE DEFINED VALUES
Java script data types are classified into following three types
1. PRIMITIVE NUMBER, STRING, BOOLEAN
2. TRIVIAL NULL, UNDEFINED
3. COMPOSITE OBJECT, ARRAY
DATA TYPES
Number
Integer, Float, NaN , Infinity
Integer Max digit 15; Float Max Digit 17
NAN != NAN;
undefined = = undefined;
null = = null;
String
Declared with single or double quotation
var a = " i am ok" // i am ok
var b = "i 'm ok" // i'm ok
var c = ' "guvi" ' // "guvi"
var d = "i am in \"the\" game" // i am in "the" game
var e = "i am in \' the game" // i am in 'the game
"2">"12" because first digit 2 is greater than 1
STRING METHODS
length
indexof
lastIndexOf (2 methods)
toUpperCase /toLowerCase
replace - 3 methods:
replace
replace with i -- ignore upper & lower cases;
replace with g -- replaces the word throughout the string(globally)
slice - 3 methods
substring and substr both are different;
substring gives the output simillar to slice
split - 3 methods -- data conversion
Boolean
True or False
Boolean (0) ('')(null)(undefined) = false
var a; (without any value)
Null
var a = null (atleast something called null)
UNDEFINED vs. NULL vs. ZERO
In undefined we never assigned any value but in the case of null at least we assign some value called null.
var a;//undefined
var b = null;
var c=5;
var d = a+c // NaN
var e = b+c //5
If I am trying to do any mathematical operation with null and number it gives me some number as output, instead of null if i am doing it with undefined and number the result is NaN
null !== 0; undefined !==0;
Array [ ]
Helps to store list of data (it allow mixed data types also).
Index starts from Zero and length starts from the count 1
It consists only numbered index.
var arrv= [1,2,3,4,5]
arr [0] = 1;
arr[5] = 6; //arr = [1,2,3,4,5,6]
arr [7] = 8; //arr = [1,2,3,4,5,6,<empty slot>,8];
arr[7] = 88; // arr =[1,2,3,4,5,6,<empty slot>,88]
length
indexof
lastIndexof
reverse
toUpperCase
toLowerCase
PUSH & POP --- deal with starting index
SHIFT & UNSHIFT --- deal with ending index
MERGING OF TWO ARRAY / CONCAT
Delete and insert @ required index using splice
slice
splice -- helps to insert or delete elements at required index.
delete
sort
Object { }
Number
String
Boolean
Undefined
Function
Object --> Object, Array, Null
*Note : Always typeof typeof (anything) is string
typeof typeof() ===> typeof (" ") ===> string
TASK
typeof(1)
typeof(1.1)
typeof("1.1")
typeof("JS")
typeof(true)
typeof(null)
typeof(undefined)
typeof([])
typeof({})
typeof(NaN)
![]() |

Comments
Post a Comment