Member-only story

3 ways to print Hello World in JavaScript

1. console.log()

Marika Lam
1 min readSep 16, 2022
<script>// using console.logconsole.log('Hello World');</script>

2. document.write()

<script>// using document.writedocument.write('Hello World');</script>

3. alert()

<script>// using alertalert('Hello World');</script>

Whenever we write javascript we make use of the ‘script’ tag. We know what a normal HTML document is made up of. The ‘script’ tag is used to write javascript code and this ‘script’ tag is either placed inside the ‘head’ tag or inside the ‘body’ tag.

Here is the HTML.

<!DOCTYPE HTML>
<html>
<head>
<title></title>
<!-- Script tag can also be placed here -->
</head>
<body>
<p>Before the script...</p><!-- Script tag inside the body -->
<script>
// write the javascript code inside it
</script>
<p>...After the script.</p></body>
</html>

Amazon Links to “Must-Haves” as a WFH Software Engineer 🙂💻

24-inch budget-friendly monitor, Portable monitor, Laptop stand, Waterproof desk mat, Keyboard cleaning gel, Six-outlet

--

--

No responses yet