Understanding JavaScript Syntax
JavaScript uses parentheses, curly braces, and semicolons as part of its basic syntax.
1console.log("Hello, user!");
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.
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.
123console.log("Command 1"); console.log("Command 2"); console.log("Command 3");
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!"?
Thanks for your feedback!
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 2.5
Understanding JavaScript Syntax
Swipe to show menu
JavaScript uses parentheses, curly braces, and semicolons as part of its basic syntax.
1console.log("Hello, user!");
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.
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.
123console.log("Command 1"); console.log("Command 2"); console.log("Command 3");
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!"?
Thanks for your feedback!