Master Node.js From Scratch

Clear, interactive, and structured Node.js lessons designed for beginners and developers.

COURSE SYLLABUS
1. Introduction to Node.js
Introduction to Node.js What Is Node.js? Node.js Architecture Features of Node.js Node.js vs Browser JavaScript Node.js Use Cases
2. Installation and Setup
Installation Introduction LTS and Current Versions npm Setup Environment Setup Verify Installation Node.js REPL
3. Node.js Fundamentals
Fundamentals Introduction Running JavaScript Global Objects Process Object Command-Line Arguments Environment Variables
4. JavaScript Basics
JavaScript Basics Introduction Variables: var, let and const JavaScript Data Types Comparison and Logical Operators If, Else If, Else and Switch Loops and Iteration Functions and Arrow Functions JavaScript Array Methods
5. Node.js Modules
Modules Introduction CommonJS Modules ES Modules Export and Import Built-in Modules Creating Custom Modules Path Module OS Module
6. Working with JSON
JSON Introduction JSON Syntax JSON.stringify() JSON.parse() JSON Array of Objects JSON User Database
7. Node Package Manager
npm Introduction package.json Installing Packages Dependencies and DevDependencies npm Scripts Package Versions and Semantic Versioning npm init and Project Setup
8. File System
File System Introduction Reading Files Writing Files Appending Files Deleting Files Working with Directories
9. CLI Applications
CLI Applications Introduction Command-Line Input Task Manager Project Structure Reading todos.json Adding, Updating and Deleting Tasks Saving Tasks to JSON
10. Events and EventEmitter
Events Introduction EventEmitter Registering Events Emitting Events Removing Event Listeners Custom Events
11. Asynchronous Programming
Async Programming Introduction Callbacks Promises async and await setTimeout() and setInterval() Event Loop and Non-Blocking I/O
12. Native HTTP Module
HTTP Module Introduction Creating an HTTP Server Handling Requests Sending Responses HTTP Request Methods Status Codes and Headers Handling POST Request Body Parsing Incoming JSON Products JSON API
13. Express.js
Express.js Introduction Installing Express Creating an Express Server Request and Response Objects Route Parameters and Query Strings Serving Static Files
14. Express Middleware
Middleware Introduction Built-in Middleware Application-Level Middleware Router-Level Middleware Custom Middleware Error-Handling Middleware
15. REST API Development
REST API Introduction GET Endpoints POST Endpoints PUT and PATCH Endpoints DELETE Endpoints Request Validation and API Responses
16. Database Integration
Database Introduction MySQL Integration MongoDB Integration Database CRUD Operations Database Queries and Filtering Connection Management
17. Authentication and Authorization
Authentication Introduction Password Hashing User Registration User Login JWT Authentication Authorization and Protected Routes
18. Advanced Node.js
Advanced Node.js Introduction Error Handling Debugging Node.js Applications Streams Buffers Performance and Security

JavaScript Comparison and Logical Operators

Learn how comparison and logical operators work in JavaScript. Understand how to compare values, combine conditions, and make decisions in real-world programs using practical examples.

1. What Are Comparison and Logical Operators?

Operators are symbols used to perform operations on values and variables. Comparison operators compare two values and return a boolean result: true or false.

Logical operators combine or reverse boolean conditions. They are commonly used in if statements, loops, validation, and application business logic.

Remember: Comparison operators help us compare values, while logical operators help us evaluate multiple conditions together.

2. JavaScript Comparison Operators

Comparison operators compare two values and produce a boolean result. JavaScript provides operators such as ===, !==, >, and <.

Operator Name Example Result
== Loose equality 5 == "5" true
=== Strict equality 5 === "5" false
!= Loose inequality 5 != "6" true
!== Strict inequality 5 !== "5" true
> Greater than 10 > 5 true
< Less than 3 < 8 true
>= Greater than or equal to 5 >= 5 true
<= Less than or equal to 4 <= 3 false
Important: Prefer === and !== for most comparisons. They compare values without the type conversion performed by loose equality operators.

3. Difference Between == and ===

The == operator can convert values to compatible types before comparing them. The === operator compares both type and value without performing that type conversion.

Example

JavaScript
let a = 10;
let b = "10";

console.log(a == b);
console.log(a === b);
console.log(a != b);
console.log(a !== b);

Output

Output
true
false
false
true

Explanation: The first comparison returns true because loose equality converts the string to a compatible number. Strict equality returns false because one value is a number and the other is a string.

4. JavaScript Logical Operators

Logical operators combine conditions or reverse a condition. They are especially useful when a program must check more than one requirement.

Operator Name Meaning Example
&& Logical AND Both conditions must be truthy. true && true
|| Logical OR At least one condition must be truthy. false || true
! Logical NOT Reverses the truthiness of a value. !true

Example

JavaScript
let age = 22;
let hasId = true;

console.log(age >= 18 && hasId);
console.log(age >= 18 || hasId);
console.log(!hasId);

Output

Output
true
true
false

The AND expression is true because both conditions are true. The OR expression is true because at least one condition is true. The NOT operator reverses the boolean value.

5. Logical Operators Truth Table

A truth table shows the result of logical operations for different combinations of boolean values.

A B A && B A || B !A
true true true true false
true false false true false
false true false true true
false false false false true

6. How Logical Conditions Work

Consider a student who can attend an advanced class only if their marks are at least 60 and they have completed the prerequisite.

Condition 1

Marks are at least 60

↓
Logical AND (&&)

Check both conditions

↓
Condition 2

Prerequisite is completed

↓
Final Result

Both conditions must be true

7. Practical Example: Student Eligibility

Let us check whether a student is eligible for an advanced course. The student must score at least 60 marks and complete the prerequisite.

Step 1: Write the Program

JavaScript
let marks = 75;
let prerequisiteCompleted = true;

let eligible = marks >= 60 && prerequisiteCompleted;

console.log("Marks:", marks);
console.log("Prerequisite Completed:", prerequisiteCompleted);
console.log("Eligible:", eligible);

Step 2: Run the Program

Terminal
node operators.js

Step 3: Expected Output

Output
Marks: 75
Prerequisite Completed: true
Eligible: true

Explanation: The marks condition is true because 75 is greater than or equal to 60. The prerequisite condition is also true. Therefore, the AND operation returns true.

8. Short-Circuit Evaluation

JavaScript logical operators use short-circuit evaluation. For AND, if the left operand is falsy, the right operand is not evaluated. For OR, if the left operand is truthy, the right operand is not evaluated.

Example

JavaScript
console.log(false && "Second value");
console.log(true || "Second value");
console.log(true && "Welcome");
console.log(false || "JavaScript");

Output

Output
false
true
Welcome
JavaScript

Logical AND and OR return operand values, not always boolean values. In the first two expressions, the right-hand operands are skipped. In the last two expressions, the right-hand values are returned.

9. Common Mistakes

Mistake Explanation Correct Approach
Using == everywhere Loose equality can convert types. Prefer === when comparing values and types.
Using && instead of || AND and OR have different meanings. Choose the operator that matches the requirement.
Confusing ! with != NOT reverses truthiness; inequality compares values. Understand each operator's purpose.
Assuming logical results are always booleans AND and OR can return operand values. Check the expression and its operands carefully.

10. Practice Task

Course Admission Eligibility

Create a JavaScript program that checks course admission eligibility.

  • Store a student's marks in a variable.
  • Store whether the student completed the prerequisite.
  • Use >= to check the minimum marks.
  • Use && to combine both conditions.
  • Use || to check an alternative eligibility condition.
  • Use ! to reverse a boolean value.
  • Display the results using console.log().
Challenge: Try different marks and prerequisite values. Predict the output before running your program.

Important Points

  • Comparison operators produce boolean results.
  • Strict equality compares type and value without type conversion.
  • Logical AND requires both operands to be truthy.
  • Logical OR returns the first truthy operand, or the last operand if none is truthy.
  • Logical NOT reverses truthiness.
  • Logical operators can skip evaluation through short-circuiting.
  • Prefer strict equality for predictable comparisons.

Summary

JavaScript comparison operators compare values, while logical operators combine or reverse conditions. Operators such as ===, !==, >, and < help compare values. The logical operators &&, ||, and ! are useful for validating multiple requirements and controlling program behavior. Understanding strict equality and short-circuit evaluation helps developers write more predictable JavaScript programs.