Variables are named containers used to store data in a program.
Data types define what kind of data a variable can hold (like numbers, text, etc).
let name = "Akshay";
let age = 30;
let isStudent = true;
let scores = [95, 99, 100];
Variable Name | Stored Value | Data Type | Explanation |
---|---|---|---|
name | "Akshay" | String | Stores a sequence of characters (text). |
age | 30 | Number | Stores numeric value. |
isStudent | true | Boolean | Stores logical value — true or false. |
scores | [95, 99, 100] | Object (Array) | Stores multiple values in an ordered list — a more complex data structure. |
Primitive Data Type: is a basic, atomic unit of data that represents a single value and is not composed of other data types. It is directly supported by the hardware or the programming language.
These are the fundamental blocks for all other data types.
Type | Description |
---|---|
Integer | Whole Numbers |
Float | Decimal or Real Numbers |
Boolean | Logical True or False values |
Character | Single alphabetic character |
Composite Data Type: is a data structure composed of multiple primitive or other composite data types, grouped together to represent more complex data.
Type | Description |
---|---|
Array | Ordered collection of same type elements (e.g., int[]) |
Object | Instance of a class with fields and methods (OOP languages) |
Abstract Data Type: is a mathematical model for data types where the data type is defined by its behaviour (operations) from the point of view of a user, not by its implementation.
ADT | Supported Operations |
---|---|
List | Insert, delete, traverse |
Stack | Push, pop, peek (LIFO) |
Queue | Enqueue, dequeue (FIFO) |
Map/Dictionary | Put, get, remove |
Set | Add, remove, contains |
Graph | Add vertex/edge, traverse, search |
An operator is a symbol or function in a programming language that tells the compiler or interpreter to perform a specific operation on one or more operands (values, variables, or expressions). Operators are fundamental to expressing logic, arithmetic, comparisons, and control flow in code.
Operators enable abstraction of low-level computation into concise, readable code constructs, making programs expressive and efficient.
Arithmetic Operators
Operator | Description | Example | Output |
---|---|---|---|
+ | Addition | 5 + 2 | 7 |
- | Substraction | 5 - 2 | 3 |
* | Multiplication | 5 * 2 | 10 |
/ | Division | 5 / 2 | 2.5 |
% | Modulus (Remainder) | 5 % 2 | 1 |
** | Exponentiation (Power) | 5 ** 2 | 25 |
++ | Increment (Increase by 1) | let x = 5; x++ | 6 |
-- | Decrement (Decrease by 1) | let x = 5; x-- | 4 |
Assignment Operators
Operator | Description | Example | Output |
---|---|---|---|
= | Assigns value | x = 5 | x = 5 |
+= | Adds and assigns | x += 3 | x = x + 3 |
-= | Subtracts and assigns | x -= 3 | x = x - 3 |
*= | Multiplies and assigns | x *= 3 | x = x * 3 |
/= | Divides and assigns | x /= 3 | x = x / 3 |
%= | Modulus and assigns | x %= 3 | x = x % 3 |
**= | Exponentiation and assigns | x **= 3 | x = x ** 3 |
Comparison Operators
Operator | Description | Example | Output |
---|---|---|---|
== | Equal to (loose check) | 5 == "5" | true |
=== | Strict equal (checks type too) | 5 === "5" | false |
!= | Not equal to | 5 != "5" | false |
!== | Strict not equal | 5 !== "5" | true |
> | Greater than | 5 > 2 | true |
< | Less than | 5 < 2 | false |
>= | Greater than or equal to | 5 >= 5 | true |
<= | Less than or equal to | 5 <= 3 | false |
Logical Operators
Operator | Description | Example | Output |
---|---|---|---|
&& | AND (Both conditions must be true) | true && false | false |
` | . | ` | OR (At least one condition must be true) |
! | NOT (Reverses the boolean value) | !true | false |
Bitwise Operators
Operator | Description | Example | Output |
---|---|---|---|
& | AND | 5 & 3 → 0101 & 0011 | 0001 (1) |
` | ` | OR | `5 |
^ | XOR | 5 ^ 3 → 0101 ^ 0011 | 0110 (6) |
~ | NOT (Inverts bits) | ~5 → ~0101 | 1010 (-6) |
<< | Left Shift | 5 << 1 (0101 << 1) | 1010 (10) |
>> | Right Shift | 5 >> 1 (0101 >> 1) | 0010 (2) |
>>> | Unsigned Right Shift | -5 >>> 1 | Large positive number |
Ternary Operator
Ternary Operator : A shorthand for if-else statements. |
---|
condition ? trueResult : falseResult; |
let age = 20; |
let canVote = (age >= 18) ? "Yes" : "No"; |
console.log(canVote); // Output: "Yes" |
Type Operators
Operator | Description | Example | Output |
---|---|---|---|
typeof | Returns the data type | typeof "Hello" | "string" |
instanceof | Checks object type | [] instanceof Array | true |
Comand | Result |
---|---|
console.log(typeof 10); | "number" |
console.log(typeof "Hello"); | "string" |
console.log(typeof true); | "boolean" |
console.log([] instanceof Array); | true |
Optional Chaining
Comand | Result |
---|---|
let user = { name: "Alice" }; | . |
console.log(user?.address?.street); | // Output: undefined (no error) |
Nullish Coalescing
Comand | Result |
---|---|
let username = null; | . |
let displayName = username ?? "Guest"; | . |
console.log(displayName); | Output: "Guest" |
Boolean Logic is a branch of algebra in which the values of the variables are true and false, typically denoted as 1 and 0, and operated on using logical operators such as AND, OR, and NOT. It is the fundamental basis of digital circuits, computer programming, search algorithms, and decision-making systems, allowing complex logical expressions to be evaluated and executed.
Propositional Calculus (also called Propositional LOgic or Sentential Logic) is a formal system in mathematical logic that deals with propositions - statements that are either true or false - and the rules for combining them using logical conectives like AND, OR, NOT, etc., to build more complex statements and reason about their truth values.
Control Structure is a syntactic construct in a programming language that allows for the regulation of the order in which instructions are executed. It includes mechanisms for conditional execution, repetition (looping), and branching, enabling developers to implement complex logic and decision-making processes. It determines what code runs, when it runs, and how often it runs.
Boolean logic and propositional calculus form the logical backbone of modern programming control structures like if, while, and for. Boolean logic allows a program to evaluate conditions as either true or false, using operators like AND (&&), OR (||), and NOT (!). Propositional calculus builds on this by defining how simple true/false statements—called propositions—can be combined into more complex expressions using formal logic rules. Together, they enable programs to make decisions, repeat tasks, and branch into different execution paths based on logical conditions.
In essence, every control flow mechanism in programming is an application of these logical foundations.
A programming paradigm is a fundamental style or methodology of programming that provides a structured approach to building and organizing code, defining how problems are solved and how program logic is expressed.
Programming Paradigms fall into two primary categories:
Imperative programming is a programming paradigm where the developer writes code that explicitly tells the computer how to perform tasks using statements that change the program's state step by step.
Subtypes of Imperative Programming -
Declarative programming is a programming paradigm where you describe what you want to achieve, not how to do it. The Logic of computation is expressed without explicitly detailing control flow.
Subtypes of Declarative Programming -
Paradigm | Key Focus | Example Concept |
---|---|---|
Procedural | Sequential instructions | for, if, function() |
OOP | Objects and state behavior | Classes, Inheritance |
Functional | Pure functions & immutability | map(), reduce() |
Reactive | Stream-based reactions | Observables, subscribe() |
Logic | Rules and facts | Pattern Matching |
Dataflow | Data availability triggers flow | Node → Edge → Node |
Object-Oriented Programming (OOP) is a programming paradigm based on the concept of "objects", which are instances of classes. These objects encapsulate data (attributes) and behaviour (methods/functions) that operate on the data.
OOP allows you to model real-world entities and relationships using abstraction, organize code into modular, reusable components, and structure programs for better scalability, maintainability and reusability.
Key Aspects:
4 pillars of OOP
class employee {
constructor(name = "", empID = 0, skills = []) {
this.name = name;
this.empID = empID;
this.skills = skills;
}
display() {
console.log(`Name = ${this.name}, Employee ID = ${this.empID}, Skills = ${this.skills.join(", ")}`);
}
}
let e1 = new employee("Akshay",1 , ["JavaScript", "React", "Node.js"]);
e1.display();
Design algorithm that clones the object instance e1 created by using employee class.
Implement the shallow clone function that creates a new object with copied top-level properties, where nested objects or arrays share refferences with the original.
Implement the deep clone function that creates a fully independent copy, including all nested structures, ensuring changes to the clone do not effect the original.
Complexity Theory is a core area of theoretical computer science that studies the efficiency of algorithms — specifically, how much time and space an algorithm needs to solve a given problem as the input size increases.
In essence, it asks:
This is critical to computer programming because developers constantly need to:
Algorithm efficiency refers to how well an algorithm uses resources—primarily time (speed) and space (memory)—as the size of its input grows.
Time complexity refers to the amount of time an algorithm takes to run as a function of the size of its input, typically denoted as n. It’s expressed in Big O notation (e.g., O(n), O(log n), O(n²)), which gives an upper bound on the growth rate of the running time.
Space complexity refers to the total memory or storage space an algorithm uses relative to the input size n. It includes space for Input data, Auxiliary variables (e.g., stacks, arrays, recursion stack), Output data (if relevant).