Learn JS:
A) Variables and Data Types:
1) Console Log:
This is used when you want to write something on your console.
SYNTAX:
console.log("This a log statement");
2) Window Alert:
This creates a pop up alert on your window.
SYNTAX:
window.alert("This is a pop up");
1) Variables in JS:
Variables are containers for data.
Example:
fullName = "Tony Stark"
console.log(fullName);
--> Variable Rules:
1) Variable names are case sensitive; "a" &"A" is different.
2) Only letters , digits, underscore(_) and $ is allowed. (not even space)
3) Only a letter, underscore(_) or $ should be 1st character.
4) Reserved words should not be used as variable names.
2) let, const & var:
var : Variables can be re-declared & updated. A global scope variables.
let : Variables cannot be re-declared but can be updated. A block scope
variable.
const : Variable cannot be re-declared or updated. A block scope
variable.
## var is the least used of them all as it was used mostly used before
2016 and also mainly because of it's syntax and it's reexecutability.
Ex:
let fullName = "Tony Stark"
console.log(fullName);
Ex:
let fullName = "Tony Stark"
console.log(fullName);
##var is a global variable which means it's value will remain the same throughout
the codewhile conast and let are only applicable inside the block({.})
2) Data Types:
A) Primitive Data Types:
1) Numbers:
Ex:
let age = 24.555;
console.log(age);
2) String:
Ex:
let fullName = "Tony Stark";
console.log(fullName);
3) Boolean:
Ex:
let statement = True;
console.log(statement);
4) Undefined:
Ex:
let x ;
console.log(x);
5) Null:
Ex:
let x = null;
console.log(x);
6) Biglnt:
Ex:
let x = BigInt("123");
console.log(x);
7) Symbol:
Ex:
let x = Symbol("Hello!");
console.log(x);
B) Non Primitive Data Types{objects}:
Objects: Collection of values.
It is a key : value system
Ex:
const student = {
fullName : "Rahul Kumar",
age : 24,
cgpa : 8.2,
isPass : true,
};
console.log(student);
Practise Questions :
Create a const object called "product" to store information shown in the picture:
const pen = {
fullName : "Parker Jotter Standard CT Ball Pen (Black)",
rating : 4 + " Out of " + 5,
price : 270,
discount : 5 + "%",
};
console.log(pen);
B) Operators:
Used to perform some operation on data.
1) Aritmetic operators:
(+, -, *, /)
Ex :
let a = 5;
let b = 2;
console.log(a + b);
i) Modulus ---> %
ii) Exponentiation ---> **
iii) Increment ---> ++
iv) Decrement ---> --
2) Assignment Operators:
( =, +=, -=, *=, %=, **= )
3) Comparision Operators: (Always returns a boolean value)
(equal to : == , equal to & type : ===,)
(not equal to : != , Not equal to & type : !==,)
(>, >=, <, <=,)
4) Logical Operators: {Based on the logic gate principle}
{ Logical AND : &&
Logical OR : ||
Logical NOT : ! }
C) Conditional Statements:
To implement some condition in the code.
1) if Statement:
let color ;
if(mode === "dark-mode") {
color = "black";
}