- Variables: A way to store values, can be assigned and reassigned.
var name = "Vamshi"; // Global Variable
let age = 23; // Local Variable
const pi = 3.14; // constant
2.Data Types: JavaScript has 7 data types: Number, String, Boolean, Null, Undefined, Object, and Symbol.
let num = 42;
let str = "Hello World";
let bool = true;
let null= null;
let undefined;
let obj = { name: "John", age: 30 };
let sym = Symbol("unique");
3.Operators: Used to perform operations on variables and values, such as arithmetic, assignment, comparison, and more.
Arithmetic operators: perform arithmetic operations such as addition (+), subtraction (-), multiplication (*), division (/), and modulus (%).
let a = 10;
let b = 5;
let c = a + b;
console.log("The value of c is:", c);
Comparison operators: compare values and return a boolean value (true or false). Examples: equal (==), not equal (!=), greater than (>), less than (<), greater than or equal to (>=), less than or equal to (<=).
let a = 10;
let b = 5;
let result = (a > b);
console.log("The result is:", result);
Logical operators: perform logical operations such as and (&&), or (||), and not (!).
let a = true;
let b = false;
let result = (a && b);
console.log("The result is:", result);
Assignment operators: assign values to variables. Examples: equal (=), add and assign (+=), subtract and assign (-=), multiply and assign (*=), and divide and assign (/=).
let a = 10;
a += 5;
console.log("The value of a is:", a);
Conditional (ternary) operator: a shorthand way of writing an if-else statement.
let a = 10;
let b = 5;
let result = (a > b) ? "a is greater than b" : "a is less than or equal to b";
console.log("The result is:", result);
Top comments (0)