Introduction To Javascript
Introduction To Javascript
Introduction to JavaScript
2. Variables
Variables are containers for storing data values. You can declare them
using let, const, or var.
Syntax:
javascript
Explanation:
3. Functions
Syntax:
javascript
function greet() {
alert("Hello, Students!");
Explanation:
Syntax:
javascript
alert("You passed!");
} else {
alert("You failed!");
Explanation:
5. Loops
Syntax:
javascript
Explanation:
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JavaScript Basics</title>
</head>
<body>
<p id="message"></p>
<script src="script.js"></script>
</body>
</html>
javascript
function sayHello() {
Explanation:
The onclick attribute in the <button> runs the sayHello() function
when clicked.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
</head>
<body>
<h1>JavaScript Demo</h1>
<p id="variable-result"></p>
<p id="loop-result"></p>
<script>
}
// Update the HTML element with the loop results
document.getElementById("loop-result").innerHTML = loopResult;
</script>
</body>
</html>