0
0
Javascriptprogramming~5 mins

Writing first JavaScript program

Choose your learning style9 modes available
Introduction

Writing your first JavaScript program helps you learn how to tell the computer what to do using code. It is the first step to creating interactive web pages.

You want to show a message on a web page.
You want to test if your computer can run JavaScript code.
You want to learn how to write simple instructions for the browser.
You want to start making websites that respond to user actions.
Syntax
Javascript
console.log('Hello, world!');

console.log() is used to show messages in the browser's console.

The text inside quotes will be shown exactly as written.

Examples
This prints the message 'Hello, world!' in the console.
Javascript
console.log('Hello, world!');
You can change the message to anything you want.
Javascript
console.log('Welcome to JavaScript!');
You can also print numbers, not just text.
Javascript
console.log(123);
Sample Program

This program prints a simple message to the console to show that JavaScript is working.

Javascript
console.log('My first JavaScript program');
OutputSuccess
Important Notes

To see the output, open your browser's developer tools and look at the console tab.

Every JavaScript statement ends with a semicolon ;, but it is optional in many cases.

Summary

JavaScript programs tell the browser what to do.

console.log() shows messages in the console.

Your first program is a simple message to check everything works.