JavaScript syntax defines the grammar rules for writing code that the engine can parse and run. Every program combines fixed literal values, named variables, operators, keywords, and expressions.
JavaScript works with two kinds of values:
42 or 3.14, strings wrapped in quotes like "Ada", and booleans like true.const or let that hold values you compute or update later.JavaScript is strictly case-sensitive. A variable named userTotal is completely different from usertotal or USERTOTAL.
Follow these naming rules so every identifier stays valid:
a-z, A-Z), an underscore (_), or a dollar sign ($).0-9) or use hyphens (-), because - means subtraction.camelCase for variables and functions, PascalCase for classes, and UPPER_SNAKE_CASE for fixed constants.const TAX_RATE = 0.08;
let itemPrice = 25;
let itemCount = 3;
function computeTotal(price, count) {
const subtotal = price * count;
return Number((subtotal * (1 + TAX_RATE)).toFixed(2));
}
console.log("Total with tax:", computeTotal(itemPrice, itemCount));
= and ===: A single = assigns a value, while === checks whether two values match in both value and type.class, return, await, and switch belong to the language and trigger a SyntaxError if used as variables.getElementbyId instead of getElementById throws a TypeError because JavaScript checks exact letter case.No, 'hello' and "hello" create identical strings. Pick one quote style for normal strings and use backticks `...` whenever you embed variables.
JavaScript parses - as the subtraction operator. Writing first-name tells the engine to subtract name from first, so use firstName instead.
SyntaxError in JavaScript?A SyntaxError happens before code runs when brackets do not match, quotes stay unclosed, or reserved keywords appear in invalid places.
Sign 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.