Java Script
Java Script
MASTERING JAVASCRIPT
WITH SURAJ YADAV FROM
BASICS TO BRILLIANCE
“A Step-by-Step Guide to Becoming a JavaScript Expert"
PAGE 1 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
DISCLAIMER
© HWS Institute of open-source university
All Rights Reserved
On the Insert tab, the galleries include items that are designed to coordinate with the
overall look of your document. You can use these galleries to insert tables, headers, footers,
lists, cover pages, and other document building blocks. When you create pictures, charts, or
diagrams, they also coordinate with your current document look. You can easily change the
formatting of selected text in the document text by choosing a look for the selected text
from the Quick Styles gallery on the Home tab.
You can also format text directly by using the other controls on the Home tab. Most controls
offer a choice of using the look from the current theme or using a format that you specify
directly. To change the overall look of your document, choose new Theme elements on the
Page Layout tab. To change the looks available in the Quick Style gallery, use the Change
Current Quick Style Set command.
Both the Themes gallery and the Quick Styles gallery provide reset commands so that you
can always restore the look of your document to the original contained in your current
template. On the Insert tab, the galleries include items that are designed to coordinate with
the overall look of your document. You can use these galleries to insert tables, headers,
footers, lists, cover pages, and other document building blocks. When you create pictures,
charts, or diagrams, they also coordinate with your current document look.
PAGE 2 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
ABOUT BOOK
© HWS Institute of open-source university
All Rights Reserved
In our book, we take you on a journey through the world of JavaScript: its core principles
and advanced concepts that let us unleash its true power. Many developers do not even
know the true nature of JavaScript and its benefits because it gets misinterpreted or
oversimplified. That will offer a comprehensive analysis of the history and future direction of
JavaScript, establishing it as one pillar upon which modern web development is built. In
addition to the syntax and features, we will touch on best practices and design patterns that
lead to clean, effective, and scalable code.
For you, that means no developer sets out to write poor code as much as how one refuses
the delight of programming. Yet, without the proper understanding of JavaScript, most
developers dig a hole leading to unsustainable codebases. This book is designed to help you
navigate through the complexities in a manner that will allow you to not only avoid these
pitfalls but also learn and master this language with greater satisfaction and
accomplishment on your coding adventure.
Think of this book as a guide that will help you on your journey to master JavaScript, with
the tools and insights that we need to overcome any obstacles lying ahead and make all the
goodness coding in JavaScript has. Whether you are working on a new project, solving tough
algorithms, or just trying to optimize your web applications, the insights shared in this book
provide valuable tips that will help both advance your skills as well as empower all of your
projects.
PAGE 3 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
ABOUT WRITER
© HWS Institute of open-source university
All Rights Reserved
Suraj understands that the pursuit of programming excellence is not without its challenges
—much like the pursuit of happiness in life. He knows that true mastery requires navigating
through the complexities, understanding the consequences of poor practices, and learning
to harness the power of JavaScript effectively. His goal is to help others avoid the pain of
common mistakes while maximizing the pleasure that comes from writing clean, efficient
code
Suraj understands that the pursuit of programming excellence is not without its challenges
—much like the pursuit of happiness in life. He knows that true mastery requires navigating
through the complexities, understanding the consequences of poor practices, and learning
to harness the power of JavaScript effectively. His goal is to help others avoid the pain of
common mistakes while maximizing the pleasure that comes from writing clean, efficient
code.
PAGE 4 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
TABLE OF CONTENTS
Chapter 1: INTRODUCTION.....................................................................
PAGE 5 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
CHAPTER 1: INTRODUCTION
If you also think that I can complete this book of 600 pages in just 6 to 7
days by covering 100 pages per day and then instantly create amazing
projects like encryption systems, libraries like React, or runtime
environments like NodeJS, then just understand that JS is not an easy task
like making pudding, you can easily complete it and create top 1% projects,
of course, you can create projects like NodeJS or React by watching tutorials
on YouTube or reading any other article but you cannot understand what is
happening in your project, you cannot understand how your project works,
so if you also want to become a top 1% JavaScript developer, then stop
cramming and take time to learn and make proper notes, understand
properly
PAGE 6 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
ECMAScript 3 (1999):
This version introduced various features like try/catch error handling and
Regular Expressions. It also paved
the way for AJAX, allowing web pages to load data in the background without
needing a refresh.
(Don’t worry if you don’t understand these terms now; we’ll cover them in
detail later.)
(2010) and React (2013) helped developers create even more complex
applications with ease.
ECMAScript 5 (2009):
In ECMAScript 5, strict mode was introduced, which helps in writing safer
code.
ECMAScript 6 (2015):
brought essential features like let and const for block-scoped variables,
arrow functions for concise Syntax, Template literals for string formatting,
classes to simplify object-oriented programming, and modules to
import/export code.
PAGE 7 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
ES7 (2016)
was a smaller update, adding two key features: the exponentiation operator
(**), which simplifies math operations, and Array.prototype.includes(),
making it easier to check if an array contains a specific element.
ES8 (2017)
expanded the language further with async/await, which made handling
promises more readable and easier to manage. It also added object features
like Object.entries() and Object.values() to work with object data
more effectively.
ES9 (2018)
introduced rest and spread properties for objects, allowing you to extract
and merge object properties easily. It also improved asynchronous code
handling with asynchronous iteration, letting developers loop over async
data streams.
ES10 (2019)
added features like Array.prototype.flat() and flatMap() to work with nested
arrays and simplified the transformation of arrays. The Optional catch
binding allowed catching errors without explicitly defining the error
parameter, making the code cleaner.
ES11 (2020)
introduced features like BigInt to handle large integers beyond the Number
type limit. The nullish coalescing operator (??) and optional chaining (?.)
provided more concise ways to handle null or undefined values without
throwing errors.
ES12 (2021)
brought improvements like logical assignment operators, which combine
logical operations and assignments. It also introduced numeric separators
(underscores in numbers) to improve readability, and Promise.any(), which
resolves the first fulfilled promise in a list.
ES13 (2022)
included Top-level await, which allowed using await in the global context,
making asynchronous code simpler in modules.
PAGE 8 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
ES14 (2023)
expanded array methods with new ways to find indices and made it easier to
work with arrays. It also added enhanced error handling, making debugging
smoother.
finalized.
Where It Is Now:
Today, JavaScript runs on clients across the globe, making it one of the most
popular programming and scripting languages, with around 95% of websites
using it. JavaScript continues to evolve, with new features being added every
year, securing its top spot in web development trends. In other words,
JavaScript has far outgrown its origins as a basic scripting language and is
now an essential tool for creating dynamic, modern web applications—a
promising sign for its future.
PAGE 9 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Interactivity:
Imagine a contact form on a website. Without JavaScript, when a user
submits the form, the entire page would need to reload to confirm if the form
was submitted successfully. JavaScript allows for form validation, where the
user receives instant feedback if they haven't filled out all required fields,
preventing unnecessary reloads. It also enables features like real-time chat
applications and dynamic content updates like search results appearing as
you type.
Dynamic Content:
Dynamic content refers to content on a webpage that can change without
reloading the entire page. For instance, JavaScript can be used to display a
random product recommendation on a homepage or update a shopping cart
total as items are added or removed. This creates a more engaging and
responsive user experience.
Accessibility:
JavaScript plays a crucial role in making websites accessible to everyone. By
supporting screen readers and keyboard navigation, developers can ensure
that users with disabilities can interact with their website effectively.
Performance: While well-written JavaScript can enhance a website's
interactivity, it's important to consider performance. Techniques like code
minification and asynchronous loading can help optimize JavaScript code to
ensure it doesn't slow down page load times.
PAGE 10 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Node.js:
While Node.js isn’t specific to client-side JavaScript, it’s essential if you want
to install libraries and tools (node packages) from the npm package
manager. Node.js also allows you to execute JavaScript on the server side.
Step-by-Step Tutorial:
How to Set Up Your JavaScript Development Environment Install a Web
Browser:
If you don’t have one, you’ll need to download and install a modern web
browser like Google Chrome or Mozilla Firefox.
Install an IDE:
Linux: You can install Node.js using your package manager. For example, on
Ubuntu, you can run sudo
PAGE 11 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
With these in place, you’re ready to start writing your JavaScript code.
Happy coding!
Note: If you find any of these steps unclear, you can refer to tutorials on
YouTube.
PAGE 12 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Keyword: -
Keywords are reserved words in JavaScript that have special meanings and
purposes within the language. They are part of the language's syntax and
cannot be used as identifiers (variable names, function names, etc.). (In
simpler terms, keywords are words that have built-in meanings in
JavaScript.)
PAGE 13 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Declaring Variables
To create a variable in JavaScript, you use the let or const keyword. This is
called declaring the variable.
const: Used for variables whose values should not change once they're set.
Example:
Assigning Values
Once you've declared a variable, you can assign a value to it using the
assignment operator (=).
Example:
Example:
console.log(name);
PAGE 14 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
var: Avoid using var in modern JavaScript. let: Use let for variables that
might change within a block. const: Use const for variables that should not
change.
Example:
// Using var
var x = 10;
x = 20; // Valid
// Using let
let y = 30;
y = 40; // Valid
// Using const
const z = 50;
In summary:
Var is generally discouraged due to its potential for unexpected behavior.
Let is flexible and allows for reassigning values. Const is used for values that
should remain constant throughout the program.
PAGE 15 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Strings:
Booleans:
Null:
Example: null
Undefined:
Represents a variable that has been declared but not yet assigned a
value.
Example:
PAGE 16 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Symbols:
Example: -
let uninitializedVariable;
PAGE 17 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
1. Objects:
Understanding Objects
Objects in JavaScript are collections of key-value pairs, where the keys are
properties and the values can be of any data type. They are used to
represent real-world entities or abstract concepts.
Creating Objects
There are two primary ways to create objects in JavaScript:
PAGE 18 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
firstName: "John",
lastName: "Doe",
age: 30,
};
person.firstName = "John",
person.lastName = "Doe",
person.age = 30,
1. Dot Notation:
console.log(person.firstName); // Output: John
2. Bracket Notation:
console.log(person["lastName"]); // Output: Doe
1.Adding Properties:
PAGE 19 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
person.occupation = "Developer";
2. Removing Properties:
Delete person.city;
person.age = 31;
Nested Objects
Objects can contain other objects as properties.
let address = {
street: "123 Main St",
city: "Anytown",
state: "CA"
};
person.address = address;
Practice Questions:
4. Nest an object representing the person's address within the person object.
PAGE 20 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Answers:
1. Create an object representing a book, with properties like title, author,
and publication year.
const book = {
publicationYear: 1954
};
const car = {
make: "Toyota",
model: "Camry",
year: 2020,
color: "Silver"
};
const person = {
age: 30,
};
const person = {
age: 30,
PAGE 21 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
address: {
city: "Anytown",
state: "CA",
zip: "12345"
PAGE 22 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
2. Arrays
Understanding Arrays
An array is a data structure that can store a collection of items in a
single list, in order.
This is why we use arrays: You can store more than one value under a
single variable name, which helps you manage the data better.
Creating Arrays
There are two primary ways to create arrays in JavaScript:
fruits[1] = "grape";
Array Length
PAGE 23 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
If you want to find The length property of an array indicates the number of
elements it contains:
console.log(fruits.length); // Output: 3
If you want to Add elements at the start of the array then you can Use
unshift() to add elements to the start of an array:
But If you want to Add elements at the End of the array then you can Use
push() to add elements to the end of an array:
Removing Elements
Now you know how to add elements in an array but now let's understand
how You can remove elements from an array:
If you want to remove elements at the start of the array then you can Use
shift() to remove elements at the start of an array:
But If you want to remove elements at the End of the array then you can Use
pop() to remove elements to the end of an array:
PAGE 24 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
PAGE 25 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
const person = {
name: "Alice",
age: 25,
isStudent: true
};
console.log(person.age); // Output: 25
In this example: person is an object with three properties (name, age, and
isStudent), storing information about a single person.
Using an Array: - A simple array can represent a list of items, such as a list
of fruits.
In this example:
PAGE 26 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
const company = {
address: {
city: "Techville",
postalCode: "12345"
},
employees: {
manager: {
age: 45,
position: "Manager"
},
engineer: {
age: 30,
};
PAGE 27 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
In this example:
Array of Objects
const users = [
];
console.log(users[1].age); // Output: 30
In this example:
PAGE 28 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
In a more advanced structure, arrays and objects are combined, with objects
containing arrays or other objects, creating a multi-level data structure.
const library = {
location: "Downtown",
books: [
available: true
},
available: false
],
staff: [
};
console.log(library.books[1].genres[0]); // Output
"Programming"
PAGE 29 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
console.log(library.staff[1].role); // Output:
"Assistant"
In this example:
Summary
PAGE 30 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Modifying another person also affects the person, as both reference the
same object in memory.
2. Arrays
Definition: An array is a data structure that can store a
collection of items in a single list, in order.
Characteristics:
Ordered collection: Each element in an array has an
index, starting from 0.
Mutable: Arrays can be modified by adding, removing,
or updating elements.
Reference-based: Like objects, arrays are reference
types, meaning assigning an array to a new variable
only copies the reference, not the actual data.
PAGE 31 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Example:
const fruits = ["apple", "banana"];
const More_Fruits = fruits; // Both variables
reference the same array
More_Fruits.push("cherry");
console.log(fruits); // Output: ["apple", "banana",
"cherry"]
PAGE 32 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
1. Arithmetic Operators
Example:
let a = 10;
let b = 3;
2. Assignment Operators
Assignment operators are used to assign values to variables.
PAGE 33 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
3. Comparison Operators
Comparison operators are used to compare two values and
return a boolean (true or false) based on the comparison result.
Common Comparison Operators:
Equal to (==): Checks if two values are equal (type
conversion occurs).
Strict Equal to (===): Checks if two values are equal and
of the same type.
Not Equal to (!=): Checks if two values are not equal
(type conversion occurs).
Strict Not Equal to (!==): Checks if two values are not
equal and of different types.
Greater than (>): Checks if the left value is greater than
the right value.
Less than (<): Checks if the left value is less than the
right value.
Greater than or equal to (>=): Checks if the left value is
greater than or equal to the right value.
Less than or equal to (<=): Checks if the left value is
less than or equal to the right value.
Example:
PAGE 34 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
4. Logical Operators
Example:
5. Bitwise Operators
PAGE 35 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Example:
Example:
7. Type Operators
Example:
PAGE 36 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
Example:
javascript
Copy code
Summary
PAGE 37 OF 38
Copyright © 2025 – HWSIOSU
MASTERING JAVASCRIPT WITH SURAJ YADAV FROM BASICS TO BRILLIANCE
PAGE 38 OF 38
Copyright © 2025 – HWSIOSU