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
Introduction to JavaScript

bookUnderstanding JavaScript Syntax

JavaScript follows a default syntax with parentheses, curly brackets, and semicolons.

Let's create a simple program and delve into its syntax. In JavaScript, you don't need to define a main function as required in languages like C, C++, Java, GoLang, etc. You can directly write your code:

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

In the example above, we've crafted a program that uses the console.log() method to print Hello, user! to the console.

Now, let's break down the syntax:

  • To begin, we employ the console.log() method. This method serves the purpose of printing values in the console;
  • Following that, we place "Hello, user!" within this method, enclosed in parentheses ();
  • The quotes (" or ') serve as indicators to JavaScript, signifying that Hello, user! is plain text and not a function or any other program-related keyword;
  • Lastly, the semicolon (;) functions as the command terminator, marking the conclusion of a command.

A program comprises a series of commands. If you intend to print text multiple times, you can utilize the semicolon ; to signal the end of each command:

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

In the example above, the semicolon ; serves as the separator for the three commands in our code:

  • The first command is console.log("Command 1") followed by ; (indicating the end of this command);
  • Subsequent commands are structured similarly.

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

JavaScript follows a default syntax with parentheses, curly brackets, and semicolons.

Let's create a simple program and delve into its syntax. In JavaScript, you don't need to define a main function as required in languages like C, C++, Java, GoLang, etc. You can directly write your code:

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

In the example above, we've crafted a program that uses the console.log() method to print Hello, user! to the console.

Now, let's break down the syntax:

  • To begin, we employ the console.log() method. This method serves the purpose of printing values in the console;
  • Following that, we place "Hello, user!" within this method, enclosed in parentheses ();
  • The quotes (" or ') serve as indicators to JavaScript, signifying that Hello, user! is plain text and not a function or any other program-related keyword;
  • Lastly, the semicolon (;) functions as the command terminator, marking the conclusion of a command.

A program comprises a series of commands. If you intend to print text multiple times, you can utilize the semicolon ; to signal the end of each command:

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

In the example above, the semicolon ; serves as the separator for the three commands in our code:

  • The first command is console.log("Command 1") followed by ; (indicating the end of this command);
  • Subsequent commands are structured similarly.

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