Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Understanding JavaScript Syntax | JavaScript Fundamentals
Practice
Projects
Quizzes & Challenges
Quizzes
Challenges
/
Introduction to JavaScript

bookUnderstanding JavaScript Syntax

JavaScript uses parentheses, curly braces, and semicolons as part of its basic syntax.

1
console.log("Hello, user!");
copy

This program prints Hello, user! to the console.

Breaking Down the Syntax

  • console.log(): a method that prints values to the console;
  • Parentheses (): hold the data you want to print;
  • Quotes " " or ' ': tell JavaScript the text is a string;
  • Semicolon ;: marks the end of the command.
Note
Note

In JavaScript, semicolons are optional because the interpreter can often insert them automatically. However, adding semicolons is a good habit, helps avoid rare errors, and keeps your code consistent.

Multiple Commands

Each command ends with a semicolon.

123
console.log("Command 1"); console.log("Command 2"); console.log("Command 3");
copy

Each line is a separate command.

1. What is the purpose of the console.log() method?

2. Why do we use quotes (" or ') around text like "Hello, user!"?

question mark

What is the purpose of the console.log() method?

Select the correct answer

question mark

Why do we use quotes (" or ') around text like "Hello, user!"?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 2

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

bookUnderstanding JavaScript Syntax

Swipe to show menu

JavaScript uses parentheses, curly braces, and semicolons as part of its basic syntax.

1
console.log("Hello, user!");
copy

This program prints Hello, user! to the console.

Breaking Down the Syntax

  • console.log(): a method that prints values to the console;
  • Parentheses (): hold the data you want to print;
  • Quotes " " or ' ': tell JavaScript the text is a string;
  • Semicolon ;: marks the end of the command.
Note
Note

In JavaScript, semicolons are optional because the interpreter can often insert them automatically. However, adding semicolons is a good habit, helps avoid rare errors, and keeps your code consistent.

Multiple Commands

Each command ends with a semicolon.

123
console.log("Command 1"); console.log("Command 2"); console.log("Command 3");
copy

Each line is a separate command.

1. What is the purpose of the console.log() method?

2. Why do we use quotes (" or ') around text like "Hello, user!"?

question mark

What is the purpose of the console.log() method?

Select the correct answer

question mark

Why do we use quotes (" or ') around text like "Hello, user!"?

Select the correct answer

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 1. ChapterΒ 2
some-alt