0% found this document useful (0 votes)
2 views3 pages

Javascript Examples

The document provides a series of examples demonstrating basic JavaScript concepts, including syntax, variables, operators, conditional statements, loops, functions, and event handling. Each example is structured as an HTML document with embedded JavaScript code to illustrate the functionality. The content serves as an introductory guide for beginners learning JavaScript programming.

Uploaded by

ching29012000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views3 pages

Javascript Examples

The document provides a series of examples demonstrating basic JavaScript concepts, including syntax, variables, operators, conditional statements, loops, functions, and event handling. Each example is structured as an HTML document with embedded JavaScript code to illustrate the functionality. The content serves as an introductory guide for beginners learning JavaScript programming.

Uploaded by

ching29012000
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1.

Basic JavaScript (Introduction & Syntax)


<!DOCTYPE html>
<html>
<head>
<title>JavaScript Introduction</title>
</head>
<body>
<h2>JavaScript Introduction</h2>
<script>
[Link]("Hello, JavaScript!");
</script>
</body>
</html>

2. Variables Example
<!DOCTYPE html>
<html>
<head><title>Variables</title></head>
<body>
<script>
var name = "John";
var age = 22;
[Link]("Name: " + name + "<br>");
[Link]("Age: " + age);
</script>
</body>
</html>

3. Operators Example
<!DOCTYPE html>
<html>
<head><title>Operators</title></head>
<body>
<script>
var a = 10;
var b = 5;
[Link](a + b);
</script>
</body>
</html>

4. If-Else Example
<!DOCTYPE html>
<html>
<body>
<script>
var marks = 65;
if(marks >= 50){
[Link]("Pass");
}else{
[Link]("Fail");
}
</script>
</body>
</html>
5. Loop Example
<!DOCTYPE html>
<html>
<body>
<script>
for(var i=1;i<=5;i++){
[Link](i + "<br>");
}
</script>
</body>
</html>

6. Function Example
<!DOCTYPE html>
<html>
<body>
<button onclick="greet()">Click</button>
<script>
function greet(){
alert("Hello!");
}
</script>
</body>
</html>

7. Function with Parameters


<!DOCTYPE html>
<html>
<body>
<script>
function add(a,b){
return a+b;
}
[Link](add(5,3));
</script>
</body>
</html>

8. Button Event
<!DOCTYPE html>
<html>
<body>
<button onclick="show()">Click</button>
<script>
function show(){
alert("Clicked!");
}
</script>
</body>
</html>
9. Form Event
<!DOCTYPE html>
<html>
<body>
<input type="text" onkeyup="show([Link])">
<p id="demo"></p>
<script>
function show(val){
[Link]("demo").innerHTML = val;
}
</script>
</body>
</html>

You might also like