๐ŸŽ“ A1Learner
๐Ÿ”

JavaScript Syntax

Syntax is the set of rules for writing a language correctly. JavaScript syntax covers values, names, and reserved words.

A literal value

Syntax rules decide how each line must be written. The number 42 here is a literal, written directly in the code.

console.log(42);

Case matters

The let word stores a value under a name. name and Name are two different identifiers here, and each holds its own value.

let name = "lower";
let Name = "upper";
console.log(name);
console.log(Name);

A camelCase name

firstName follows the camelCase habit. The name starts lowercase, and the second word starts with a capital.

let firstName = "Ana";
console.log(firstName);

Example

let userName = "Bo";
let userAge = 9;
console.log(userName);
console.log(userAge);
console.log("Done");

Key points

  • Value: a piece of data, like a number or a piece of text
  • Literal: a fixed value written directly in the code
  • Identifier: a name given to a variable or a function
  • JavaScript is case-sensitive, so name and Name are two different names.
  • camelCase: a naming style that starts lowercase and caps each later word, like firstName
  • Keyword: a word the language reserves for its own use, like let

In this example, the first statement stores the literal Bo under the name userName. The second statement stores the literal 9 under the name userAge. The next two statements print the two stored values. The last statement prints the literal text Done.

Try it Yourself

Edit the code, then press Run.

Runs in your browser โ€” the preview under the editor is the real result. Nothing is sent to a server. The code runner panel (right) does the same with more room.

Exercise

Which pair holds two different identifiers?