Java Script in my Understanding
Basics of Javascript.
1) How to Declare the variables in JS ?
We use var, let, const keyword before declaring a variable.
Avoid using var because of issue in block scope and functional scope.
JS is kind enough to declare variable without keywords but it's not a best practice.
const name = 'pramod';
let age = 19;
var email = 'pramodambati1@gmail.com';
city = hyderabad
let state; // undefined
2) what all the datatypes in JS?
There are two type of datatypes in JS.
1) Primitive Data types
2) Non-Primitive (Reference) Data types
Primitive Data types
const name = 'pramod'; // String
let age = 22; // Number
let isLoggedIn = false; // Boolean
let state; // Undefined
let temperature = null; // null (Representation of empty value)
let bigNumber = 10494917943941985n; // Big Int
let isSym = Symbol('test'); // Symbol
const id = Symbol('123')
const anotherId = Symbol('123') // Generate Unique Symbol.
console.log(id === anotherId) // false
// Strict Check === checks datatype not only its value
console.log(2 == '2'); // true
console.log(2 === '2'); // false
2) Reference Datatype
Reference is directly allocated to the memory.
// Array, Object, Function
const heros = ['IronMan', 'BatMan', 'SuperMan']
const myObj = {
name = 'pramod',
age = 22
}
const myFunction = funtion() {
return 'Hello World';
}
3) Return Type of Datatypes in JS.
/*
Return type of Datatypes in JavaScript
1) Primitive Datatypes
Number => number
String => string
Boolean => boolean
null => object
undefined => undefined
Symbol => symbol
BigInt => bigint
2) Non-primitive Datatypes
Arrays => object
Function => function // we call it as object function
Object => object
https://262.ecma-international.org/5.1/#sec-11.4.3
*/
3) Primitive and Refernce In JS?
let firstName = 'pramod'
let anotherName = firstName
another name = 'James'
console.log(firstName) // 'pramod'
console.log(anotherName) // 'James'
let userOne = {
email: "pramod@gmail.com",
upiId: "9390095818"
}
let userTwo = userOne
userTwo.email = 'pramodambati1@gmail.com'
console.log(userOne.email) // pramodambati1@gmail.com
console.log(userTwo.email) // pramodambati1@gmail.com
// Primitive values goes into stack and whenever you take something inside the stack, you get only a copy of it.
// Where as in Heap you w/ill get reference change you make or update , you do it in the original value only.

Credits: Chai Aur Code JS Playlist.
