Day 1 of JavaScript Mastery

Table of contents
- Welcome to Day 1 of my JavaScript Mastery Journey! ๐โจ
- The Story of JavaScript (Simple & Interesting) ๐๐ก
- The Mission: Make the Web Interactive! ๐ฏ๐ป
- The Birth of Mocha โ LiveScript โ JavaScript โ๐โจ
- Why JavaScript? ๐ค
- So, What is JavaScript? ๐งฉ
- JavaScript is a Scripting Language โ What Does That Mean? ๐ง
- JavaScript Today โ A Global Hero! ๐๐ฆธ
- JavaScript Versions โ ES5 vs ES6 ๐
- Fun Fact: ๐ง ๐ก
- Summary for Interviews about the History of JS ๐ฏ๐
- Tips to Remember ๐๐
- What is JavaScript? ๐
- Engines that Run JS ๐ ๏ธ๐๏ธ
- JavaScript in Action ๐ฌ๐
- Tools for Frontend Dev ๐งฐ๐ฉโ๐ป
- First JS Program ๐ปโจ
- Structure of a JavaScript File ๐๐
- External vs Inline JS ๐๐
- JS Comments ๐ฌ
- JavaScript with Node.js โก๏ธ๐ณ
- Fun Fact! ๐ง ๐ก
- Simple Analogy ๐งฉ๐ถ
- What is Node.js? ๐
- DOM Manipulation with JavaScript ๐งฑโจ
- Variables in JavaScript ๐งฎ
- JavaScript Data Types ๐ฆ๐
- Summary โ

Welcome to Day 1 of my JavaScript Mastery Journey! ๐โจ
Author: Ravindranath Porandla โ๏ธ
The Story of JavaScript (Simple & Interesting) ๐๐ก
Once upon a timeโฆ ๐ฐ๏ธ
In 1995, the internet was growing fast. People used to browse websites that were static โ like reading a printed book. ๐ฐ boring! ๐ด
But then came a superhero named Brendan Eich ๐จโ๐ป, who was working at a company called Netscape (one of the earliest web browsers). ๐
The Mission: Make the Web Interactive! ๐ฏ๐ป
Netscape wanted to make websites interactive โ like when you click a button and something happens, or type into a form and get suggestions. ๐คฉ
So, they told Brendan:
โHey! Can you make a small scripting language for our browser in 10 days?โ ๐คฏ (Yes, just 10 days!)
Brendan said:
โSure! Iโll do it in 10 days.โ ๐ช (What a legend!)
The Birth of Mocha โ LiveScript โ JavaScript โ๐โจ
He first called the language Mocha (like the coffee โ, as there was a trend of giving languages the names of coffee like Java). Then it became LiveScript โโก Finally, it was renamed to JavaScript โ๐ (And the rest is history!)
Why JavaScript? ๐ค
Because Java was very popular at that time, they thought (as a business tactic ๐):
"Letโs name it JavaScript โ itโll sound like a mini Java! or an extended version of Java." clever, right? ๐
โ ๏ธ But Java and JavaScript are NOT the same (just like a car and carpet aren't the same ๐๐งถ). Big difference!
So, What is JavaScript? ๐งฉ
JavaScript is a scripting language used to make websites interactive. โจ
Imagine a human body: ๐ง
HTML is the skeleton ๐ฆด (the structure)
CSS is the flesh and dress you wear ๐ (the style)
JavaScript is the movement of the body, the actions ๐คธ (the behavior!)
JavaScript is a Scripting Language โ What Does That Mean? ๐ง
Letโs break it down: โฌ๏ธ
Types of Languages ๐ค
Type | Meaning | Example |
Markup Language | Used to structure content | HTML |
Style Sheet Language | Used to style content | CSS |
Scripting Language | Used to add behavior | JavaScript |
Programming Language | Used to build full software apps | Java, C++, Python |
JavaScript Today โ A Global Hero! ๐๐ฆธ
โ It became the universal language of the web ๐ โ Runs in all browsers (Chrome, Firefox, Safari, etc.) ๐ฆ๐ฆ โ Used in frontend, backend, mobile apps, games, AI, and more! ๐ฑ๐ฎ๐ง (Truly versatile!)
JavaScript Versions โ ES5 vs ES6 ๐
What is ES? ๐ค
ES stands for ECMAScript โ the official name of JavaScriptโs versioning system. ๐
Think of it like iPhone models: ๐ฑ
ES5 = iPhone 5 ๐ฑ (the classic)
ES6 = iPhone 6 ๐ (newer, cooler, more features!)
ES5 (2009) ๐ฐ๏ธ
The old school ๐ซ
Works on all browsers ๐
Features:
var
,Object.keys()
, JSON, strict mode (you will be learning these as you progress in learning JS) ๐ค
ES6 (2015) โ The Game Changer! ๐ฎโจ
Introduced modern, cleaner ways to write code ๐งน
Features: (you will be learning these as you progress in learning JS)
let
andconst
instead ofvar
(better variable handling!)Arrow functions
()=>
(shorter syntax!)Template literals (backticks
Hello ${name}
) (easy strings!)class
syntax (object-oriented goodness!)import
/export
(module system!)Promises (for async code) ๐ค
Destructuring (unpacking values easily!)
Fun Fact: ๐ง ๐ก
Brendan Eich made JavaScript in just 10 days. ๐คฏ Thatโs why there were bugs, weird rules, and many ways to do the same thing. ๐ But over time, JavaScript evolved beautifully into one of the most powerful languages in the world! ๐๐
Summary for Interviews about the History of JS ๐ฏ๐
Point | Quick Notes |
Who created JS | Brendan Eich in 1995 |
Original name | Mocha โ LiveScript โ JavaScript |
Why the name | To ride the popularity of Java |
Type of language | Scripting (runs in browsers) |
Used for | Making web pages interactive |
Java vs JavaScript | Totally different |
ES5 | Older version of JS |
ES6 | Modern JS with new features |
Tips to Remember ๐๐
๐ก Think of JS as the language of the web โ runs in all browsers ๐ ๐ Learn ES6 โ most interview questions are based on modern JS ๐ ๐ซ Donโt confuse Java and JavaScript ๐ โโ๏ธ ๐ฌ Try using JS in the browser console (right-click โ Inspect โ Console) ๐งโ๐ป
What is JavaScript? ๐
JavaScript is a programming language that runs in browsers and makes websites interactive. โจ
๐ Example:
When you click "Add to Cart" and it instantly updates โ that's JavaScript in action! ๐๐จ
๐ก Tip:
HTML builds the structure ๐๏ธ, CSS styles it ๐จ, and JavaScript brings it to life! ๐
Engines that Run JS ๐ ๏ธ๐๏ธ
Engine | Used In |
V8 | Chrome, Node.js |
SpiderMonkey | Firefox |
JavaScript in Action ๐ฌ๐
Try this in the browser console: ๐
console.log("Hello World"); // Prints a message to the console
alert("Welcome!"); // Displays a pop-up alert
clear(); // Clears the console
Tools for Frontend Dev ๐งฐ๐ฉโ๐ป
Why VS Code? ๐
Lightweight, open-source, and highly customizable ๐จ
Preferred by most frontend developers ๐
Why not IntelliJ / PyCharm (Community)? โ
Limited frontend features ๐
Slower setup for React/JavaScript ๐ข
First JS Program ๐ปโจ
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>My First JS</title>
</head>
<body>
<h1>Hello World!</h1>
</body>
<script>
console.log("Hello World from JS");
</script>
</html>
Structure of a JavaScript File ๐๐
Explanation:
JavaScript files contain statements, not HTML tags. ๐
JS is written inside
<script>
tags. โ๏ธScripts can be placed in
<head>
or after<body>
. โฌ๏ธโฌ๏ธ
Difference:
If placed in
<head>
, the script runs before the DOM (Document Object Model, for now think of this as HTML) is loaded, which can cause errors if it tries to access elements that arenโt loaded yet. ๐ซ When using JavaScript, you typically interact with HTML elements to make them interactive. Therefore, running JS before HTML is fully loaded can cause errors. ๐If placed after
<body>
, it ensures the HTML is fully loaded before JS runs. โ
Best Practice: ๐
Always place your script just before the closing </html>
tag or use defer
in the <script>
tag within <head>
, which ensures HTML loads first before JS runs. ๐
<script src="index.js" defer></script>
๐ก Tip:
Let HTML load first โ then run JavaScript! ๐โโ๏ธ๐จ
External vs Inline JS ๐๐
Explanation:
Inline JS is written directly in HTML. โก๏ธ
External JS is in a
.js
file and linked via<script src="">
. โฌ ๏ธ
๐ก Tip:
Keep logic in external files to separate concerns and keep code clean. ๐งผโจ
JS Comments ๐ฌ
JavaScript
// Single-line comment
/* Multi-line comment */
/**
* Doc-style comment
* Use jsdoc.app for documentation
* Refer to the web to learn more about Doc-style comments
*/
Note: When you hover over an inbuilt method or a function, you will see what the function does, what parameters it takes, and what it returns. This is achieved using Doc-Style comments. โน๏ธ
Doc-style (JSDoc) comment โ commonly used for documentation: ๐
/**
* Adds two numbers together.
* @param {number} a - First number
* @param {number} b - Second number
* @returns {number} Sum of a and b
*/
function add(a, b) {
return a + b;
}
JavaScript with Node.js โก๏ธ๐ณ
History of Node.js โ The Journey of JavaScript on the Server ๐ฐ๏ธ๐บ๏ธ
๐ฑ Before Node.js
JavaScript was born in 1995 and was only used in browsers for frontend tasks like button clicks, animations, etc. ๐ฑ๏ธ You couldnโt run JavaScript outside the browser, which meant backend work (like databases, file access) needed languages like PHP, Java, Python, etc. ๐พ
2009 โ Birth of Node.js! ๐
๐จโ๐ป The Creator: Ryan Dahl
A software engineer named Ryan Dahl noticed that traditional server software (like Apache) couldnโt handle multiple connections efficiently. ๐ข He wanted something faster and non-blocking (i.e., able to handle many requests without waiting). ๐
๐ก The Idea
โWhy not run JavaScript outside the browser?โ ๐ค He picked Googleโs V8 engine (used in Chrome) to run JavaScript on the server. ๐๏ธ And boom! Node.js was born in 2009. ๐ฅ
What does it mean:
โTraditional server software (like Apache) couldnโt handle multiple connections efficientlyโ? ๐ง
๐งโ๐ณ Analogy: The Single Chef Kitchen ๐ฝ๏ธ
Imagine a restaurant (server) with just one chef (thread): ๐จโ๐ณ
One customer (request) comes โ Chef starts cooking. ๐ณ
Another customer comes โ Chef says โWait! Iโll finish the first order first.โ โณ
So, others wait in a queue. ๐ถโโ๏ธ๐ถโโ๏ธ๐ถโโ๏ธ
This is how traditional servers like Apache often worked:
They either created a new thread for each request (which used more memory) ๐ง , or
They processed one request at a time (which was slow for many users). ๐
๐ง So what's the problem?
If 1000 users connect at once: ๐ฅ๐ฅ๐ฅ
Apache may create 1000 threads (heavy for memory) ๐คฏ, or
Make others wait (slow performance). ๐ฉ
Thatโs why we say:
โApache couldnโt handle multiple connections efficiently.โ ๐
Now, Node.js Style: The Multi-Tasking Chef! ๐งโ๐ณโจ
Node.js uses a smart trick called non-blocking I/O: ๐ช
The chef says: โWhile that dish is baking, Iโll start chopping veggies for the next one.โ ๐ฅ๐ง
No one waits! All tasks move forward together โ faster & lighter. ๐๐จ
โ Conclusion:
Apache = good, but heavy & not ideal for real-time or high-traffic apps. ๐ฆ
Node.js = light, fast, handles many users at once without blocking others. ๐
What Made Node.js Special? ๐๐
Non-blocking I/O: It doesnโt wait for one task to finish before starting another. Like a chef cooking many dishes at once. ๐จโ๐ณ concurrently!
Event-driven: Works on events and callbacks, like "when done, call this function." ๐
Single-threaded but super efficient โ ideal for real-time apps like chat, live updates, APIs. ๐ฌ๐
Node.js Takes Over the World! ๐๐
Initially, it was used by startups. ๐ข Then big companies joined: Netflix, LinkedIn, PayPal, Uber. ๐ Developers loved writing frontend + backend in the same language โ JavaScript. ๐
npm (Node Package Manager) ๐ฆโจ
Along with Node.js came npm โ a treasure box of ready-made code (modules/packages). ๐ Think of it like an โapp store for developers.โ ๐ฑ๐๏ธ
Key Milestones ๐งฑ๐๏ธ
Year | Milestone |
2009 | Node.js launched by Ryan Dahl |
2010 | npm introduced |
2011 | Microsoft and Joyent joined the project |
2014 | io.js forked from Node.js for faster updates |
2015 | io.js and Node.js merged again (Node.js 4.0) |
Now | Widely used across backend, APIs, full-stack apps |
Fun Fact! ๐ง ๐ก
Ryan Dahl later admitted some regrets and created a new project called Deno (an anagram of Node). ๐
Simple Analogy ๐งฉ๐ถ
Imagine JavaScript as a kid who was only allowed to play indoors (browser). ๐ Ryan Dahl came along and said, โWhy not let him explore the outside world too?โ ๐ณ That outside world became Node.js! ๐
What is Node.js? ๐
Node.js is a runtime environment that allows you to run JavaScript outside the browser, using Googleโs V8 engine. ๐ปโ๏ธ
๐ Example:
With Node.js, JavaScript can be used for backend scripting like reading files, accessing databases, and more. ๐๐๏ธ
๐ง Commands:
node -v # check version ๐
node index.js # run your JavaScript file โถ๏ธ
๐ก Tip:
Think of Node as a server-side version of JavaScript. Great for full-stack! ๐๐งโ๐ป
DOM Manipulation with JavaScript ๐งฑโจ
What is DOM? (we will learn more as we progress) ๐
DOM (Document Object Model) is a representation of HTML elements as objects. JavaScript can interact with it to change content or style. ๐จโ๏ธ
๐ Example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1 id="heading">Hello!!!!!</h1>
<button id="click">click</button>
</body>
<script src="index.js"></script>
</html>
document.getElementById('click').onclick = function(){
document.getElementById('heading').innerText = 'Hello World!!!!!!!!!!';
};
What is actually happening here? ๐ค When you click the button, the text in h1
changes from โHello!!!!!โ to โHello World!!!!!!!!โ ๐ฅ
๐ก Tip:
You can also manipulate style.backgroundColor
๐, hide elements ๐ป, or dynamically create new ones using DOM APIs. โจ
Variables in JavaScript ๐งฎ
var
- old version of Java ES5 ๐ด let
and const
- introduced in newer version of Java ES6 ๐งโ๐ค We can use all 3 currently. ๐
Definitions: ๐
Feature | var | let | const |
Scope | Function-scoped | Block-scoped | Block-scoped |
Re-declaration | Allowed | Not allowed | Not allowed |
Re-assignment | Allowed | Allowed | Not allowed |
Hoisting | Yes (initializes to undefined ) | Yes (but not initialized) | Yes (but not initialized) |
Attached to window object? | Yes | No | No |
๐ Note: Youโll get to learn more about Hoisting and the Window Object as you progress. ๐ค
๐ก Tips:
Use
UPPERCASE
for constants. โฌ๏ธPrefer
let
andconst
overvar
. โFollow naming conventions: โ๏ธ
camelCase
orsnake_case
for variablesUpperCamelCase
for functions
โ ๏ธ Rules for Naming: ๐ซ
Start with a letter,
$
, or_
. ๐ ฐ๏ธ๐ฒNo spaces or special characters. ๐ โโ๏ธ
Avoid reserved keywords (like
return
,if
). ๐
JavaScript Data Types ๐ฆ๐
Primitive Types: ๐น
Number โ 1, 3.14 ๐ข
String โ 'hello', "name" ๐ฌ
Boolean โ true, false โ โ
Undefined โ variable declared but not assigned โ
Null โ intentional absence of value ๐ซ
Reference Types: ๐ธ
Object โ key-value pairs ๐
Array โ list of items (internally, arrays are objects) ๐
Function - A callable object that can be stored in variables, passed as arguments, and returned from other functions. (You will learn all types of functions as you progress). โ๏ธ
Reference values are data types in JavaScript where only the reference (address in memory) is assigned to another variable, not the actual copy of the data. This means changes made through one reference affect the original value. ๐
๐ Hint: If the value has brackets (like []
, {}
, or functions ()
), itโs usually a reference type. ๐ก
Example: ๐งช
let arr1 = [1, 2, 3];
let arr2 = arr1;
arr2.push(4); // Adding 4 to arr2
console.log(arr1); // Output: [1, 2, 3, 4] (arr1 also changed!)
console.log(arr2); // Output: [1, 2, 3, 4]
Here, arr1
and arr2
point to the same array in memory, so changes in arr2
reflect in arr1
. ๐ค
Primitive Types: ๐
Primitives (like numbers, strings, booleans) are copied by value: ๐ข๐ฌโ
let x = 10;
let y = x;
y = 20; // Changing y
console.log(x); // Output: 10 (x remains unchanged!)
console.log(y); // Output: 20
Here, x
and y
are independent, since primitives store actual values, not references. ๐งโโ๏ธ๐งโโ๏ธ
Key Difference from Primitive Types โจ
Primitive Types | Reference Types |
Stored by value | Stored by reference |
Immutable | Mutable |
Copied on assignment | Reference is copied |
๐ก Tip:
Use typeof
to check type: ๐ต๏ธโโ๏ธ
console.log(typeof "hello"); // string
console.log(typeof [1, 2, 3]); // object
Summary โ
Today, we covered: โ
The Story of JavaScript: ๐๐ก
Its creation in 1995 by Brendan Eich at Netscape in just 10 days! ๐คฏ
The evolution of its name (Mocha โ LiveScript โ JavaScript) and the business tactic behind it. โ๐
A crucial clarification that Java and JavaScript are NOT the same. โ ๏ธ
What JavaScript Is: ๐งฉ
Defined as a scripting language used to make websites interactive. โจ
An analogy comparing HTML (skeleton), CSS (flesh/dress), and JavaScript (movement/actions) of a human body. ๐ง
A breakdown of different language types: Markup, Style Sheet, Scripting, and Programming. ๐ค
JavaScript Today โ A Global Hero: ๐๐ฆธ
Its status as the universal language of the web, running in all browsers. ๐
Its widespread use in frontend, backend, mobile apps, games, and AI. ๐ฑ๐ฎ๐ง
JavaScript Versions โ ES5 vs ES6: ๐
Explanation of ECMAScript (ES) as JavaScript's versioning system. ๐
Comparison of ES5 (2009) as the "old school" version and ES6 (2015) as the "game-changer" that introduced modern features like
let
/const
, arrow functions, template literals,class
syntax, Promises, and more. ๐
Setting up and Running JavaScript: ๐ ๏ธ
Recommendation of VS Code as the preferred lightweight, customizable editor. ๐
Demonstration of a basic HTML file with an inline
<script>
tag. ๐ปExplanation of JavaScript file structure and the difference between placing scripts in
<head>
vs. after<body>
(with best practices likedefer
). ๐The distinction between External vs. Inline JS and the tip to keep logic in external files. ๐
How to use JS Comments for documentation (
//
,/* */
,/** */
). ๐ฌ
JavaScript with Node.js: โก๏ธ๐ณ
The history of Node.js, created by Ryan Dahl in 2009, enabling JavaScript to run outside the browser using Google's V8 engine. ๐ก
A detailed analogy of the "Multi-Tasking Chef" to explain non-blocking I/O and event-driven architecture, highlighting Node.js's efficiency compared to traditional server software. ๐งโ๐ณโจ
The importance of npm (Node Package Manager) as a "treasure box" of ready-made code. ๐ฆ
Key milestones in Node.js's development and its global adoption. ๐๐
A simple analogy comparing JavaScript in the browser to a kid playing indoors, and Node.js to exploring the outside world. ๐งฉ๐ถ
DOM Manipulation with JavaScript: ๐งฑโจ
An introduction to the Document Object Model (DOM) as a representation of HTML elements that JavaScript can interact with to change content or style. ๐จโ๏ธ
A practical example showing how to change text on a button click. ๐
Variables in JavaScript: ๐งฎ
A comparison of
var
(ES5) vs.let
andconst
(ES6), outlining differences in scope, re-declaration, re-assignment, and hoisting. ๐Tips for best practices in naming and choosing variable types (
let
/const
preferred). โ๏ธ
JavaScript Data Types: ๐ฆ๐
Categorization into Primitive Types (Number, String, Boolean, Undefined, Null) which are copied by value. ๐น
Categorization into Reference Types (Object, Array, Function) which are copied by reference, illustrated with an example to show how changes in one reference affect the original. ๐ธ
The key difference between how primitive and reference types are stored and copied. โจ
The use of
typeof
to check data types. ๐ต๏ธโโ๏ธ
Follow more at: Ravindranath Porandla Blog ๐ง ๐
โ Ravindranath Porandla ๐งโ๐ป
Subscribe to my newsletter
Read articles from Ravindranath Porandla directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
