JavaScript for Beginners

About Course
What is JavaScript ?
JavaScript is a high-level, interpreted programming language primarily used to create interactive and dynamic content on websites. It runs directly in your browser and works alongside HTML and CSS to make web pages come alive.
-
HTML = structure (bones)
-
CSS = style (clothes)
-
JavaScript = behavior (actions and movement)
JavaScript was originally created just for web browsers, but now it’s also used on servers, apps, games, and even hardware using platforms
What are the usage of JavaScript ?
- Web Development (Frontend)
- Server-side Development (Backend)
- Mobile App Development
- Game Development
- Desktop App Development
- Automation & Scripting
How JavaScript Works in the Browser ?
HTML Loads First
-
When you open a webpage, your browser loads and reads the HTML first.
-
This builds the structure of the page: headings, paragraphs, images, buttons, etc.
CSS Styles the Page
-
Then CSS is applied to style the page: colors, fonts, layout, animations.
JavaScript is Executed
-
The browser finds
<script>
tags in the HTML, and runs the JavaScript code. -
It can be inside the HTML or in a separate
.js
file.
JavaScript Interacts with the DOM
-
The DOM (Document Object Model) is the browser’s internal representation of the page.
-
JavaScript can access and modify the DOM:
-
Change text, colors, or images
-
Add or remove elements
-
Respond to events like clicks or key presses
-
Example :
<!DOCTYPE html>
<html>
<head><title>My Page</title></head>
<body>
<button onclick=“sayHello()”>Click me!</button>
<script>
function sayHello() {
alert(“Hello from JavaScript!”);
}
</script>
</body>
</html>