JavaScript syntax defines the set of rules for structuring valid code. JavaScript is case-sensitive, uses the Unicode character set, and distinguishes between fixed values (literals) and variable storage containers (variables).
flowchart TD
Syntax["JavaScript Syntax Rules"] --> Case["Case Sensitivity: myVar !== myvar"]
Syntax --> Ident["Identifiers: Must start with Letter, $, or _"]
Syntax --> Literals["Literals: Fixed values (42, 'Hello', true, {id: 1})"]
Syntax --> Keywords["Reserved Keywords: let, const, function, class"]
| Naming Pattern | Standard Convention | Example |
|---|---|---|
| Variables & Functions | Lower Camel Case (lowerCamelCase) |
calculateTotalPrice, userEmail |
| Classes & Constructors | Upper Camel Case (PascalCase) |
UserAccount, OrderManager |
| Constants (Global) | UPPER_SNAKE_CASE | MAX_RETRY_ATTEMPTS, API_BASE_URL |
| Private Fields (ES2022) | Prefix Hash (#) |
#privateSecret, #token |
// Syntax Demo: Literals, Identifiers, and Case Sensitivity
// Fixed Literals
const NUMBER_LITERAL = 100.50;
const STRING_LITERAL = "KodSolution Tutorial";
const BOOLEAN_LITERAL = true;
const ARRAY_LITERAL = ["HTML", "CSS", "JavaScript"];
const OBJECT_LITERAL = { domain: "kodersolution.com", status: 200 };
// Identifier Case Sensitivity Demonstration
let userScore = 95;
let UserScore = 40; // Completely distinct variable from userScore
console.log(`userScore: ${userScore}, UserScore: ${UserScore}`);
// Valid Identifier Characters (Letters, $, _)
let $element = document.querySelector("#app"); // Valid prefix $
let _internalState = "idle"; // Valid prefix _
let user10 = "Valid numeric suffix"; // Numbers allowed after first char
console.log(`State: ${_internalState}, Tag: ${user10}`);
myFunction and myfunction refer to two completely different memory locations.let 1stUser = "Alex" will trigger a SyntaxError.isEmailValidated over vague variables like chk.Which of the following identifier names are invalid in JavaScript?
_userStatus2ndPlace$accountBalanceuser-nameSign in to track your learning journey, earn industry-recognized certificates, and join our elite developer community.
Quick Access With
Experiment with the code from this lesson in our interactive playground.