📜  javascript hello world - Javascript (1)

📅  最后修改于: 2023-12-03 14:42:25.122000             🧑  作者: Mango

JavaScript Hello World

JavaScript is a popular programming language used for developing web applications, games, and more. In this tutorial, we will learn how to create a simple Hello World program using JavaScript.

Writing the Program

Open a new file named hello.js and type the following code:

console.log("Hello World!");

This code will print the text "Hello World!" to the console. Save the file and open it in a web browser.

Running the Program

To run the program, open the browser's developer tools and navigate to the console. On Windows, you can do this by pressing F12 or Ctrl + Shift + I. On macOS, press Cmd + Opt + I.

Type node hello.js into the console and press Enter. The message "Hello World!" should be printed to the console.

Alternatively, you can run the program in a web page by creating an HTML file and adding a script tag to it. For example:

<!DOCTYPE html>
<html>
<head>
  <title>Hello World!</title>
</head>
<body>
  <h1>Hello World!</h1>

  <script src="hello.js"></script>
</body>
</html>

This HTML file includes a script tag that references the hello.js file we created earlier. When you open the HTML file in a web browser, the "Hello World!" message will be printed to the console and displayed on the page.

Conclusion

Congratulations, you have created your first JavaScript program! This simple program may not seem like much, but it is the foundation for more complex applications. Keep practicing and exploring the world of JavaScript.