DEV Community

Vamshi Krishna
Vamshi Krishna

Posted on

JavaScript Key fundamentals Part - 1

  1. 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 

Enter fullscreen mode Exit fullscreen mode

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");

Enter fullscreen mode Exit fullscreen mode

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);

Enter fullscreen mode Exit fullscreen mode

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);

Enter fullscreen mode Exit fullscreen mode

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);

Enter fullscreen mode Exit fullscreen mode

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);

Enter fullscreen mode Exit fullscreen mode

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);

Enter fullscreen mode Exit fullscreen mode

Top comments (0)