Hello World in JavaScript

JavaScript is one of the most popular programming languages for web development. If you’re just starting with JavaScript, the first program you’ll likely create is the classic “Hello, World!” example. This simple program helps you understand how to output text using JavaScript.

Here’s how you can write and execute your first JavaScript code:

Writing “Hello, World!” in JavaScript

  1. Using the Console: Open your browser’s developer tools (usually accessible with F12 or Ctrl + Shift + I) and go to the console tab. Type the following code:javascriptCopyEditconsole.log("Hello, World!"); Press Enter, and you’ll see “Hello, World!” displayed in the console.
  2. Embedding in HTML: You can also write JavaScript directly in an HTML file. Create a file named index.html and add the following code:htmlCopyEdit<!DOCTYPE html> <html> <head> <title>Hello World in JavaScript</title> </head> <body> <h1>Hello World Example</h1> <script> document.write("Hello, World!"); </script> </body> </html> Open this file in a browser, and “Hello, World!” will appear on the webpage.

Understanding the Code

  • console.log: This method is used to print messages to the browser’s console. It’s handy for debugging and testing.
  • document.write: This function writes directly to the webpage. However, it’s less commonly used in modern web development.

Start experimenting with these basics, and you’ll be ready to dive deeper into JavaScript programming. Happy coding! 😊

Previous
Next

More Amazing Post

Get 15GB free hosting with Infinity Free

  • January 23, 2025

hosting is a compulsory thing for publish a website....

author-avatar
Posted By nazir

Programming Languages and Their Frameworks

  • January 20, 2025

Programming languages and frameworks go hand-in-hand to simplify and...

author-avatar
Posted By nazir

Uses of C#

  • January 20, 2025

C# (pronounced as “C-Sharp”) is a versatile and powerful...

author-avatar
Posted By nazir
Scroll to Top