logo CBCE Skill INDIA

Welcome to CBCE Skill INDIA. An ISO 9001:2015 Certified Autonomous Body | Best Quality Computer and Skills Training Provider Organization. Established Under Indian Trust Act 1882, Govt. of India. Identity No. - IV-190200628, and registered under NITI Aayog Govt. of India. Identity No. - WB/2023/0344555. Also registered under Ministry of Micro, Small & Medium Enterprises - MSME (Govt. of India). Registration Number - UDYAM-WB-06-0031863

How to write first code in JavaScript?


How to write first code in JavaScript?
 

To write your first code in JavaScript, you can start with a simple example that demonstrates the basics of the language. Here's a classic "Hello, World!" program in JavaScript:

 

  1. Using an HTML file:

Create an HTML file, and within the <script> tags, write your JavaScript code. Open the HTML file in a web browser to see the output.

 

HTML file (example.html):

<!DOCTYPE html>
<html>
<head>
    <title>My First JavaScript Code</title>
</head>
<body>

    <h1>My First JavaScript Code</h1>

    <script>
        // JavaScript code
        console.log("Hello, World! This is my first JavaScript code.");
    </script>

</body>
</html>
  1. Using a separate JavaScript file:

Create a JavaScript file (example.js) and link it to an HTML file.

 

HTML file (index.html):

<!DOCTYPE html>
<html>
<head>
    <title>My First JavaScript Code</title>
    <script src="example.js"></script>
</head>
<body>
    <h1>My First JavaScript Code</h1>
</body>
</html>

 

JavaScript file (example.js):

// JavaScript code in example.js
console.log("Hello, World! This is my first JavaScript code.");

 

 

When you open the HTML file in a web browser, open the developer console (usually by right-clicking and selecting "Inspect," then navigating to the "Console" tab) to see the output of your JavaScript code.

The console.log() function in JavaScript is used to output text or other data to the console, allowing you to see the result of your code execution.

These basic examples introduce you to the process of writing and running JavaScript code. They demonstrate how to output a simple message in the console, which is a good starting point for learning the language.

 

Thank you.


Give us your feedback!

Your email address will not be published. Required fields are marked *
0 Comments Write Comment