Example

Hello World in JavaScript

HTML

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
	<title>Hello World in JavaScript</title>
</head>
<body>

	<h1>Demo: Hello World in JavaScript</h1>

	<p><strong>NOTE: To display the alert() message, view output in the full window!</strong></p>
	<p><strong>To display the console.log() message, view output in the web console log!</strong></p>

	<p id="para"></p>

	<!-- JavaScript Code begins here -->
	<script>

		// Using alert() method - alert box with a message
		alert("Hello World - By alert() method");

		// Using write() method - write content to the Document  
		document.write("Hello World - By write() method");

		// Using log() method - write message to the console  
		console.log("Hello World - By console.log() method");

		// Using DOM selection & manipulation
		document.getElementById("para").innerHTML = 
		"Hello World - By DOM selection & manipulation";
		
	</script>


</body>
</html>

Output

View original