Introduction to JavaScript
1. Introduction
JavaScript is a scripting language that adds interactivity to web pages. It is used for dynamic
behavior like form validation, animations, and event handling.
2. JavaScript Syntax
JavaScript can be written inside an HTML file using the <script> tag:
<script>
alert('Hello, JavaScript!');
</script>
3. Variables and Functions
- Declaring variables:
var name = 'John';
let age = 25;
const PI = 3.14;
- Functions:
function greet() {
alert('Welcome to JavaScript!');
4. Sample Program: Interactive Button
<!DOCTYPE html>
<html>
<head>
<title>JavaScript Example</title>
</head>
<body>
<h2>Click the button</h2>
<button onclick='showMessage()'>Click Me</button>
<script>
function showMessage() {
alert('Hello! You clicked the button.');
</script>
</body>
</html>