JS Syntax
let variableName = value;
function functionName(parameter) {
return value;
}
object.property
Values
A value is a single piece of data that JavaScript can work with, such as a number, a piece of text, or true and false, and values are the raw material every JavaScript program manipulates.
Example: Values
// Print `5` to the console
// Print `5` to the console
console.log(5);
// Print "hello" to the console
// Print "hello" to the console
console.log("hello");
// Print `true` to the console
// Print `true` to the console
console.log(true);
Operators
Operators are symbols that perform actions on values, such as + to add numbers or join text, and = to assign a value to a variable, forming the connective tissue between values in an expression.
Example: Operators
console.log(2 + 3);
console.log("Hello" + " World");
Expressions
An expression is any piece of code that produces a value, ranging from a simple literal to a complex combination of operators and function calls, and expressions are the pieces statements are built from.
Example: Expressions
let result = 2 + 3 * 4;
console.log(result);
Keywords and Identifiers
Keywords are reserved words with special meaning in JavaScript, like const, function, and if, that you cannot use as your own names, while identifiers are the custom names you choose for variables, functions, and other pieces of your code.
Example: Keywords and Identifiers
const userEmail = "[email protected]";
console.log(userEmail);
Case Sensitivity and camelCase
JavaScript is fully case sensitive, meaning userName and username are treated as two entirely different identifiers, and the community convention for naming variables and functions is camelCase, where the first word is lowercase and each following word starts with a capital letter.
Example: Case Sensitivity and camelCase
// Declare the variable `userName`, set to "Alice"
// Declare the variable `userName`, set to "Alice"
let userName = "Alice";
// Declare the variable `username`, set to "Bob"
// Declare the variable `username`, set to "Bob"
let username = "Bob";
// Print `userName, username` to the console
// Print `userName, username` to the console
console.log(userName, username);
- Using a reserved keyword, like class or return, as a variable name, which causes an immediate syntax error.
- Mixing up case sensitivity, JavaScript treats myVariable and myvariable as two completely different identifiers.
- Starting an identifier with a number, valid identifiers must begin with a letter, underscore, or dollar sign.
- Values, operators, expressions, and keywords are the fundamental building blocks of JavaScript syntax.
- Identifiers are the names given to variables, functions, and other entities, and they follow specific naming rules.
- JavaScript is case sensitive, and camelCase is the standard naming convention for variables and functions.
Core JavaScript syntax rules, values, operators, expressions, and identifier rules, are part of the language standard and behave identically in every browser.
Chapter Quiz — Complete all 12 topics to unlock
0/12 topics done
Complete these topics first: