JavaScript 1
JavaScript 1
Introduction to JavaScript
JavaScript runs in web browsers and enables client-side functionality, such as:
Form validation
Interactive animations
---
Example:
<h1>Welcome to My Website</h1>
<p>This is a paragraph.</p>
h1 {
color: blue;
font-size: 24px;
}
3. JavaScript (JS)
It can modify HTML and CSS, respond to user input, and handle events.
Example:
Comparison Table
---
Characteristics of JavaScript
1. Interpreted Language – JavaScript does not need to be compiled and runs directly in
browsers.
2. Lightweight and Fast – Since it is executed within the browser, it does not require extra
resources.
3. Event-Driven – JavaScript can respond to user actions like clicks, mouse movements, and
keyboard input.
8. Client-Side Execution – Executes on the user’s browser without needing server interaction.
9. Can Manipulate the DOM – JavaScript can dynamically change HTML and CSS.
---
Example:
Example:
<html>
<body>
<p id="demo">Welcome!</p>
<script>
document.getElementById("demo").innerHTML = "Hello, JavaScript!";
</script>
</body>
</html>
Example:
<html>
<body>
<p id="demo">Welcome!</p>
<script src="script.js"></script>
</body>
</html>
---
Best Practice: Use external JavaScript for better organization and performance, especially for
large applications.
---
Conclusion
JavaScript is a powerful scripting language that makes websites dynamic and interactive. It
works alongside HTML and CSS to create engaging web applications. Understanding how to
integrate JavaScript (inline, internal, external) and its characteristics will help in building efficient
web applications.