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 Data Types

Learn the different data types available in JavaScript, including strings, numbers, booleans, undefined, null, BigInt, Symbol, and objects, with practical examples and expected outputs.

1. What Are Data Types?

A data type describes the kind of value stored or processed by a program. JavaScript uses data types to determine how values behave during operations and calculations.

For example, a student's name is usually stored as a string, marks can be stored as a number, and a result can be represented using a boolean value.

Remember: JavaScript is dynamically typed. A variable declared using let can hold a value of one type and later be reassigned a value of another type.

2. Classification of JavaScript Data Types

JavaScript data types are broadly classified into primitive types and objects.

JavaScript Data Types

All values used in JavaScript programs

↓
Primitive Types

String, Number, Boolean, Undefined, Null, BigInt, and Symbol

↓
Object Type

Objects, arrays, functions, and other object values



Note: Functions are callable objects, and arrays are specialized objects in JavaScript.

3. String Data Type

A string represents text. JavaScript strings can be written using single quotes, double quotes, or backticks.

Example

JavaScript
let studentName = "Samadhan";
let course = 'JavaScript';
let message = `Welcome to ${course}`;

console.log(studentName);
console.log(course);
console.log(message);

Output

Output
Samadhan
JavaScript
Welcome to JavaScript

Explanation: The first two variables store text. The third example uses a template literal, which allows the value of course to be inserted using ${course}.

4. Number Data Type

The Number type represents integers and floating-point numbers. JavaScript uses the same Number type for both.

Example

JavaScript
let age = 22;
let price = 149.50;

console.log(age);
console.log(price);
console.log(typeof age);
console.log(typeof price);

Output

Output
22
149.5
number
number

Explanation: Both variables use the Number type. JavaScript does not have separate primitive types for ordinary integers and decimals. The console may display 149.50 as 149.5 because trailing zeros are not significant in a numeric value.

5. Boolean Data Type

A boolean represents one of two values: true or false. Booleans are commonly used in conditions and decision-making statements.

Example

JavaScript
let isStudent = true;
let hasCompletedCourse = false;

console.log(isStudent);
console.log(hasCompletedCourse);
console.log(typeof isStudent);

Output

Output
true
false
boolean

Boolean values are useful when checking whether a student passed, whether a user is logged in, or whether a condition is satisfied.

6. Undefined Data Type

A variable declared without assigning a value has the value undefined. It can also be assigned explicitly.

Example

JavaScript
let result;

console.log(result);
console.log(typeof result);

Output

Output
undefined
undefined

Explanation: The variable result is declared but no value is assigned to it. Therefore, its value is undefined, and typeof result also returns the string "undefined".

7. Null Data Type

The value null is used to represent an intentional absence of a value. It can be useful when a value is not currently available or has deliberately been cleared.

Example

JavaScript
let selectedCourse = null;

console.log(selectedCourse);
console.log(typeof selectedCourse);

Output

Output
null
object
Important: typeof null returns "object" because of a historical JavaScript behavior. However, null is a primitive value, not an object.

8. BigInt Data Type

BigInt is used to represent integers larger than the range in which JavaScript Number can represent every integer precisely. A BigInt literal can be written by adding n at the end of an integer.

Example

JavaScript
let largeNumber = 9007199254740993n;

console.log(largeNumber);
console.log(typeof largeNumber);

Output

Output
9007199254740993n
bigint

BigInt and Number should not be mixed directly in ordinary arithmetic operations. Convert values carefully when working with both types.

9. Symbol Data Type

Symbol creates a unique primitive value. Symbols are often used as property keys when a unique identifier is required.

Example

JavaScript
let id1 = Symbol("id");
let id2 = Symbol("id");

console.log(id1 === id2);
console.log(typeof id1);

Output

Output
false
symbol

Although both symbols use the same description, each call to Symbol() creates a distinct symbol value.

10. Object Data Type

An object stores related information as properties and values. Objects are commonly used to represent students, employees, products, and other entities in applications.

Example: Object

JavaScript
let student = {
    name: "Samadhan",
    age: 22,
    course: "JavaScript"
};

console.log(student.name);
console.log(student.age);
console.log(student.course);
console.log(typeof student);

Output

Output
Samadhan
22
JavaScript
object

Example: Array

JavaScript
let courses = ["JavaScript", "Node.js", "React"];

console.log(courses[0]);
console.log(courses.length);
console.log(typeof courses);
console.log(Array.isArray(courses));

Output

Output
JavaScript
3
object
true

Arrays store ordered collections of values. JavaScript reports their type as "object", so Array.isArray() is a useful way to check whether a value is an array.

11. Understanding the typeof Operator

The typeof operator returns a string indicating the type category of a value. It is useful when inspecting values during development.

Example

JavaScript
console.log(typeof "Hello");
console.log(typeof 100);
console.log(typeof true);
console.log(typeof undefined);
console.log(typeof 100n);
console.log(typeof Symbol("id"));
console.log(typeof {});
console.log(typeof function () {});

Output

Output
string
number
boolean
undefined
bigint
symbol
object
function

Remember: typeof has special cases, including typeof null === "object". Use the appropriate checks for arrays, null values, and other special cases.

12. Practice Task

Student Information Program

Create a JavaScript program that:

  • Stores a student's name as a string.
  • Stores the student's age and marks as numbers.
  • Stores the pass status as a boolean.
  • Declares one variable without assigning a value.
  • Creates an object containing student details.
  • Uses typeof to inspect different values.
  • Uses Array.isArray() to check an array.
Challenge: Create two symbols with the same description and verify whether they are equal.

Important Points

  • JavaScript has seven primitive types.
  • String represents text, Number represents ordinary numeric values, and Boolean represents true or false.
  • Undefined commonly indicates an unassigned value; null represents an intentional absence of value.
  • BigInt supports large integers, while Symbol creates unique primitive values.
  • Objects can group related information into properties.
  • Arrays and functions are object-related values with special behavior.
  • typeof null returns "object" because of a historical JavaScript behavior.

Summary

JavaScript provides seven primitive types: string, number, boolean, undefined, null, bigint, and symbol. Objects store related properties and values, while arrays represent ordered collections. The typeof operator helps inspect values, but special cases such as null and arrays require additional understanding. Knowing data types helps us write correct calculations, conditions, and application logic.