Primitives and Objects
π§Ά Tags:: #JavaScript
π Resources:: YouTube | Replit
2023-09-04 - 02:35
There are 7 types of data types -
NNBBSSU
NULL
NUMBER
SYMBOL
STRING
BOOLEAN
BIGINT
UNDEFINED
// NN BB SS U
let a = null;
let b = 2;
let c = true;
let d = BigInt("567") + BigInt("3");
let e = "EXIA";
let f = Symbol("I'm nice");
let g = undefined
console.log(a, b, c, d, e, f, g)
console.log(typeof e) // string
// Objects on JS
const item = {
"varun": true,
"Josh": 55,
"Pushkar": undefined
}
console.log(item["varun"]); // true
// create a data type string and try to add a number to it
let example = "master";
let h = example + 30;
console.log(typeof h) // string
const items = {
"varuni": true,
}
let varuni = 3;
console.log(varuni) // 3
const dictionary = {
"apple": "a fruit",
"wheat": "a type of grain",
"car": "A type of vehicle",
"bike": "A type of vehicle!",
"earth": "The planet we live on",
}
console.log(dictionary.apple) // a fruit
console.log(dictionary.wheat) // a type of grain
console.log(dictionary.car) // a type of vehicle
console.log(dictionary.bike) // a type of vehicle
console.log(dictionary.earth) // The planet we live on
// chapter 1 - Q1
let x = "varun"
let y = 6
console.log(x + y) // when you add 2 things in a string format they concatenate
// Chapter 1 - Q2
console.log(typeof (x+y))
// chapter 1 - Q3
const t = {
name: "varun",
section: 1,
isPrincipal: false
}
t['code name'] = 'exia' // adding key value to an const, you can add and change keys inside an object
t['name'] = "varun2" // changing key value { name: 'varun2', section: 1, isPrincipal: false, 'code name': 'exia' }
console.log(t)