JavaScript

Write your first Hello, World! in JavaScript

In learning programming languages, we start with the “Hello, World!” “. This is a simple program that displays the phrase “Hello, World!”. To announce you’re coming into the programming world. We will see how to write this type of program in JavaScript. It will be a single statement that displays the phrase “Hello, world!” On a dialog box.
 

How to add JavaScript to a page

Web browsers are designed to understand HTML, CSS, and also JavaScript. You must therefore tell it precisely where the JavaScript code is located using the <script> tag.

The <script> tag is an HTML tag. It acts like an interpreter that actually says “Hi browser, here is some JavaScript code”. When the web browser encounters the closing </script> tag, it knows it has reached the end of the JavaScript program and can return to its normal tasks.

Most of the time, you will add the <script> tag to the <head> section of a web page, like this:

<html>
	<head>
		<title>My web page</title>
		<script type="text/javascript">
			// Put your Javascript code here.
		</script>
	</head>
</html>

Then you add your JavaScript code between the opening and closing <script> tags.
 

 

Create a “Hello, World!” program using the alert() function

The alert() function in JavaScript is an order that opens an alert box and displays the message that appears in parentheses. Example: Create a file named “hello.html” and write the following code in it.

<html>
	<head>
		<title>My web page</title>
		<script type="text/javascript">
			alert('hello world!');
		</script>
	</head>
</html>

Open a web browser and open the “hello.html” file. You will get an alert box like this:
 

 

Conclusion

Now you know how to write a classic “Hello, World!” You can improve your program by reading the following articles:
mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *