Skip to main content
Introduction to JavaScript
A Beginner's Guide to the Language of the Web
Prepared By: Kale J. N.
July 17, 2026 | Page 1 of 31
What is JavaScript?
• High-level, interpreted programming language
• Enables interactivity in web pages
• Runs in the browser (client-side)
• Multi-paradigm: supports procedural, object-oriented, and functional styles
• One of the three core web technologies, alongside HTML and CSS
• No compilation step required — code runs directly
Prepared By: Kale J. N.
July 17, 2026 | Page 2 of 31
History of JavaScript
• Created in 1995 by Brendan Eich at Netscape
• Originally called Mocha, then LiveScript
• Became JavaScript to ride Java's popularity
• Standardized as ECMAScript
• The first version was written in just 10 days
• ECMAScript is maintained by ECMA International (TC39 committee)
• New editions are released annually (e.g., ES2015, ES2023)
Prepared By: Kale J. N.
July 17, 2026 | Page 3 of 31
Where JavaScript Runs
• Browsers (Chrome, Firefox, Edge, etc.)
• Server-side using Node.js
• Mobile apps (React Native)
• Desktop apps (Electron)
• IoT and hardware projects (e.g., Johnny-Five)
• Command-line tools and automation scripts
Prepared By: Kale J. N.
July 17, 2026 | Page 4 of 31
Why Use JavaScript?
• Makes websites interactive
• Can update and change HTML/CSS
• Validate form input
• Build games, animations, apps
• Handles asynchronous tasks for a smoother user experience
• Backed by a massive ecosystem of libraries via npm
Prepared By: Kale J. N.
July 17, 2026 | Page 5 of 31
JavaScript vs Java
• Java: Compiled, statically typed
• JavaScript: Interpreted, dynamically typed
• Despite the name, they're very different!
• Java runs on the Java Virtual Machine (JVM); JavaScript runs in browser engines
• Java is common for enterprise/backend systems; JavaScript dominates the web
• The naming similarity was a marketing decision, not a technical relationship
Prepared By: Kale J. N.
July 17, 2026 | Page 6 of 31
Popular Use Cases
• Web applications (e.g., Gmail, Facebook)
• Frontend frameworks (React, Angular, Vue)
• Server-side apps (Node.js)
• Game development
• E-commerce platforms (Amazon, Shopify)
• Progressive Web Apps (PWAs)
• Real-time apps like chat and collaboration tools
Prepared By: Kale J. N.
July 17, 2026 | Page 7 of 31
How JavaScript Works
• Embedded in HTML using <script> tag
• Browser has a JS engine (e.g., V8 in Chrome)
• JS code is interpreted and executed line-by-line
• The engine parses code into an Abstract Syntax Tree (AST)
• Just-In-Time (JIT) compilation improves performance
• The event loop manages asynchronous operations
Prepared By: Kale J. N.
July 17, 2026 | Page 8 of 31
Basic JavaScript Syntax
<script>
alert('Hello, World!');
</script>
• Semicolon ends statements
• Case-sensitive
• Code runs top to bottom
• Variables are declared using let, const, or var
• Comments use // for single-line or /* */ for multi-line
• Curly braces { } define blocks of code
Prepared By: Kale J. N.
July 17, 2026 | Page 9 of 31
JavaScript Data Types
Understanding How JavaScript Stores and Handles Values
Prepared By: Kale J. N.
July 17, 2026 | Page 10 of 31
Introduction
• What are Data Types?
• Define the type of data a variable can hold
• JavaScript is dynamically typed
• Types determine what operations are valid on a value
• JavaScript automatically converts types when needed (type coercion)
• A variable can hold different types at different times
Prepared By: Kale J. N.
July 17, 2026 | Page 11 of 31
Two Categories
• JavaScript data types are divided into:
• 1. Primitive Data Types
• 2. Non-Primitive (Reference) Data Types
• Primitive types are stored by value
• Non-primitive types are stored by reference
• This distinction matters for comparisons and copying behavior
Prepared By: Kale J. N.
July 17, 2026 | Page 12 of 31
Primitive Data Types
• Immutable and hold single values
• Types include: String, Number, Boolean, Undefined, Null, BigInt, Symbol
• Immutable means the value itself can't change, only reassigned
• Each primitive has a matching wrapper object (e.g., String, Number)
• Compared by value, not by reference
Prepared By: Kale J. N.
July 17, 2026 | Page 13 of 31
String
let name = "Sai";
• Textual data enclosed in quotes
• Example: "Hello", 'A', `Backtick`
• Strings are immutable once created
• Template literals (backticks) allow easy interpolation: `Hi ${name}`
• Built-in methods include .length, .toUpperCase(), .slice()
Prepared By: Kale J. N.
July 17, 2026 | Page 14 of 31
Number
let age = 25;
let price = 99.99;
• Integers and floating-point
• Special values: Infinity, -Infinity, NaN
• JavaScript uses one Number type for both integers and decimals (IEEE 754)
• No separate int/float types unlike many other languages
• Use Number.isInteger() to check for whole numbers
Prepared By: Kale J. N.
July 17, 2026 | Page 15 of 31
Boolean
let isStudent = true;
• Only two values: true or false
• Used in conditions
• Result of comparison operators like ==, ===, >, <
• Central to control flow: if, while, ternary expressions
Prepared By: Kale J. N.
July 17, 2026 | Page 16 of 31
Undefined and Null
let x; // undefined
let y = null; // null
• Undefined: declared but not assigned
• Null: explicitly no value
• typeof undefined is "undefined"; typeof null is "object" (a well-known JS quirk)
• null == undefined is true, but null === undefined is false
Prepared By: Kale J. N.
July 17, 2026 | Page 17 of 31
BigInt
let big = 12345678901234567890n;
• BigInt: for very large integers
• Introduced in ES2020
• Cannot mix BigInt and Number in arithmetic without explicit conversion
Prepared By: Kale J. N.
July 17, 2026 | Page 18 of 31
Non-Primitive Data Types
• Hold collections or complex entities
• Types: Object, Array, Function
• Stored by reference in memory
• Can represent multiple values and complex structures
• Copying a reference type copies the reference, not the underlying data
Prepared By: Kale J. N.
July 17, 2026 | Page 19 of 31
Object Example
let person = {
name: "John",
age: 30
};
• Key-value pairs
• Mixed data types
• Accessed via dot notation (person.name) or bracket notation (person["name"])
• Can contain nested objects and even functions (methods)
Prepared By: Kale J. N.
July 17, 2026 | Page 20 of 31
Array Example
let fruits = ["Apple", "Banana", "Mango"];
• Ordered list
• Can store different types
• Technically a special type of object with numeric indices
• Common methods: .push(), .map(), .filter(), .length
Prepared By: Kale J. N.
July 17, 2026 | Page 21 of 31
Function Example
function greet() {
return "Hello";
}
• Functions are first-class citizens — they can be stored and passed around
• Can be defined as declarations, expressions, or arrow functions
• Reusable blocks that help organize logic
Prepared By: Kale J. N.
July 17, 2026 | Page 22 of 31
typeof Operator
console.log(typeof "Hi"); // string
console.log(typeof 123); // number
• Used to check data types
• typeof an array returns "object", not "array" — use Array.isArray() instead
• Helpful for debugging and validating input types
Prepared By: Kale J. N.
July 17, 2026 | Page 23 of 31
Functions in JavaScript
Building Reusable and Modular Code
Prepared By: Kale J. N.
July 17, 2026 | Page 24 of 31
What is a Function?
function name(params) {
// code
}
• A block of reusable code
• Used to perform a particular task
• Helps avoid repetition, following the DRY principle (Don't Repeat Yourself)
• Can accept inputs (parameters) and return outputs
Prepared By: Kale J. N.
July 17, 2026 | Page 25 of 31
Function Declaration
function greet() {
console.log('Hello');
}
• Can be called before it's defined (hoisting)
• Best suited for defining reusable, named functions
• Hoisting moves the function definition to the top of its scope
Prepared By: Kale J. N.
July 17, 2026 | Page 26 of 31
Function Expression
const greet = function() {
console.log('Hello');
};
• Stored in a variable
• Not hoisted
• Useful for defining functions conditionally or passing them as values
• Can be named or anonymous
Prepared By: Kale J. N.
July 17, 2026 | Page 27 of 31
Default Parameters
function greet(name = 'Guest') {
console.log('Hello ' + name);
}
greet(); // Hello Guest
greet('abc'); // Hello abc
• Introduced in ES6
• Helps avoid undefined errors when arguments are omitted
• Default values can reference earlier parameters
Prepared By: Kale J. N.
July 17, 2026 | Page 28 of 31
Arrow Functions (ES6)
const add = (a, b) => a + b;
• Shorter syntax
• Do not have their own 'this' binding — they inherit it from the surrounding scope
• Cannot be used as constructors (no 'new' keyword)
Prepared By: Kale J. N.
July 17, 2026 | Page 29 of 31
Callback Functions
function process(callback) {
callback();
}
function greet() {
console.log('Hello');
}
process(greet);
• Function passed as an argument to another function
• Common in array methods like .map(), .forEach(), .filter()
• Foundation for understanding Promises and async/await
Prepared By: Kale J. N.
July 17, 2026 | Page 30 of 31
Why Use Callbacks?
• Handle asynchronous operations
• Reuse logic in higher-order functions
• Enable non-blocking code execution
• Were the standard async pattern before Promises and async/await existed
Prepared By: Kale J. N.
July 17, 2026 | Page 31 of 31