🧠 The First Step in JavaScript
Writing "Hello World" is a classic tradition for learning any programming language. In JavaScript, it’s your first step toward building interactive web pages and apps. Let’s learn how to do it in different environments!
🔤 1. Hello World in Browser Console
This is the simplest way to get started with JavaScript — right in your browser!
Using DevTools Console
console.log("Hello, World!");Note
🌐 2. Hello World in HTML File
You can include JavaScript inside an HTML file using the <script> tag. This is great for beginners learning how JavaScript interacts with web pages.
hello.html
<!DOCTYPE html>
<html>
<head>
<title>Hello JS</title>
</head>
<body>
<h1>Hello from HTML!</h1>
<script>
console.log("Hello, World from script!");
</script>
</body>
</html>Note
🖥️ 3. Hello World with Node.js
If you have Node.js installed, you can run JavaScript outside the browser using your terminal or command prompt.
hello.js
// hello.js
console.log("Hello, Node.js World!");Then run it using:
Terminal Command
node hello.jsNote
🎉 What Just Happened?
- console.log() is a built-in function that prints messages to the console
- It's used for debugging, checking values, and displaying text
- The message appears in the browser’s developer console or in your terminal (Node.js)
🚀 Next Steps
- ✅ Try editing your message: console.log("Hello, YourName!");
- ✅ Create a function to greet someone
- ✅ Learn how JavaScript interacts with HTML elements (DOM)
📚 Helpful Resources
🧠 Summary
Writing “Hello World” is your initiation into JavaScript development. Whether it’s in a browser, HTML file, or Node.js terminal, it shows you how to write and execute your first line of code. From here, the entire JavaScript universe awaits you! 🌌