-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIntroduction-HelloWorld
47 lines (29 loc) · 1.08 KB
/
Introduction-HelloWorld
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
JavaScript Program To Print Hello World
In this example, you will learn to print 'Hello World' in JavaScript in three different ways.
A "Hello, World!" is a simple program that prints Hello, World! on the screen. Since it's a very simple program, this program is often used to introduce a new programming language to beginners.
We will use these three ways to print 'Hello, World!'.
console.log()
alert()
document.write()
1. Using console.log()
console.log() is used in debugging the code.
Source Code
// the hello world program
console.log('Hello World');
Output
Hello, World!
Here, the first line is a comment.
// the hello world program
The second line
console.log('Hello, World!');
prints the 'Hello, World!' string to the console.
2. Using alert()
The alert() method displays an alert box over the current window with the specified message.
Source Code
// the hello world program
alert("Hello, World!");
3. Using document.write()
document.write() is used when you want to print the content to the HTML document.
Source Code
// the hello world program
document.write('Hello, World!');