Programming Concepts

1. Variables and Data Types

  • Variable: is a named storage location in memory that holds a value which can be retrieved, modified, or used during program execution. Variables abstract the actual memory management so that developers can work with human-readable names instead of memory addresses.
  • Data Type: A data type is a classification that specifies which type of value a variable can hold, and what operations can be performed on that value. Data types ensure correctness, optimization, and memory efficiency in software design. It acts as a constraint and a blueprint for how data is stored, interpreted, and manipulated in memory.

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 NameStored ValueData TypeExplanation
name"Akshay"StringStores a sequence of characters (text).
age30NumberStores numeric value.
isStudenttrueBooleanStores 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.

TypeDescription
IntegerWhole Numbers
FloatDecimal or Real Numbers
BooleanLogical True or False values
CharacterSingle 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.

TypeDescription
ArrayOrdered collection of same type elements (e.g., int[])
ObjectInstance 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.

ADTSupported Operations
ListInsert, delete, traverse
StackPush, pop, peek (LIFO)
QueueEnqueue, dequeue (FIFO)
Map/DictionaryPut, get, remove
SetAdd, remove, contains
GraphAdd vertex/edge, traverse, search

2. All Operators

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.

Operators

Arithmetic Operators

Operator DescriptionExampleOutput
+ Addition5 + 2 7
-Substraction5 - 2 3
*Multiplication5 * 2 10
/Division5 / 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 DescriptionExampleOutput
= 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 DescriptionExampleOutput
== 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 DescriptionExampleOutput
& 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
ComandResult
console.log(typeof 10);"number"
console.log(typeof "Hello");"string"
console.log(typeof true); "boolean"
console.log([] instanceof Array);true

Optional Chaining

ComandResult
let user = { name: "Alice" };.
console.log(user?.address?.street); // Output: undefined (no error)

Nullish Coalescing

ComandResult
let username = null;.
let displayName = username ?? "Guest";.
console.log(displayName); Output: "Guest"

3. Control Structure

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.

4. Programming Paradigms

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 Paradigm
  • 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 -

    1. Procedural Programming
    2. Object-Oriented Programming OOP
    3. Parallel/Concurrent Programming
  • Declarative Programming Paradigm
  • 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 -

    1. Functional Programming
    2. Logic Programming
    3. Reactive Programming
    4. Dataflow Programming
    ParadigmKey FocusExample Concept
    ProceduralSequential instructionsfor, if, function()
    OOPObjects and state behaviorClasses, Inheritance
    FunctionalPure functions & immutabilitymap(), reduce()
    ReactiveStream-based reactionsObservables, subscribe()
    LogicRules and factsPattern Matching
    DataflowData availability triggers flowNode → Edge → Node

5. Object-Oriented Programming

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:

  • Everything is treated as an object.
  • Programs are designed around interacting objects, rather than just functions or logic.
  • Data hiding, inheritance, polymorphism, and encapsulation are the foundational concepts.

4 pillars of OOP

  • Encapsulation - Hiding internal state and requiring all interaction to be performed through methods.
  • Inheritance - Mechanissm where one class inherits from another.
  • Abstraction - Exposing only essential features and hiding implementations details.
  • Polymorphism - Ability for different classes to be treated as instances of the same parent class.

6. Mastering Object Cloning


  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.

7. Complexity Theory

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:

  • How “hard” is a problem to solve?
  • Can we solve it efficiently?
  • What is the best possible performance we can get?

    This is critical to computer programming because developers constantly need to:

  • Choose the right algorithms.
  • Write efficient code that performs well even with large inputs.
  • Understand trade-offs between performance and accuracy.

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