JavaScript is a powerful and widely-used programming language that allows developers to create dynamic and interactive web applications. It is commonly used for:
- Adding interactivity to websites (e.g., buttons, forms, animations)
- Manipulating HTML & CSS dynamically
- Building full-stack applications with frameworks like React, Angular, and Node.js
JavaScript is essential for web development because:
- It runs directly in the browser (client-side scripting)
- It can interact with HTML & CSS to create dynamic UI changes
- It has vast community support and powerful libraries (like jQuery, React, and Vue.js)
JavaScript code runs inside a browser using a JavaScript engine. Some popular browsers and their JavaScript engines are:
- Chrome → V8 Engine
- Firefox → SpiderMonkey
- Safari → JavaScriptCore
To write JavaScript, you can use:
- Inline JavaScript (inside an HTML file)
- Internal JavaScript (inside a
<script>
tag in HTML) - External JavaScript File (
.js
file)
<!DOCTYPE html>
<html>
<head>
<title>My First JS</title>
</head>
<body>
<h1>Welcome to JavaScript</h1>
<script>
alert("Hello, JavaScript!");
</script>
</body>
</html>
Create a file intro.js
and add the following code:
console.log("Welcome to JavaScript!");
alert("Hello from an external JS file!");
Now link this file in an HTML file like this:
<script src="intro.js"></script>
- Browser Console: Open Chrome, right-click → Inspect → Console.
- HTML file: Write JavaScript inside
<script>
tags and open the HTML file. - Node.js: Install Node.js and run
node intro.js
in the terminal.
- JavaScript makes websites dynamic and interactive.
- It runs inside browsers using JavaScript engines.
- You can write JavaScript inline, inside HTML, or in an external file.
Now, move to the next chapter to learn about Variables in JavaScript! 🚀