Unit content
JavaScript programming
JavaScript is a general-purpose programming language used widely in web browsers and also in server and command-line environments.
Variables and values
Modern JavaScript commonly binds names with const or let:
const name = "Ada";
let count = 3;
const prevents rebinding the name, while let allows reassignment.
Control flow
JavaScript uses braces to delimit blocks:
if (count > 0) {
console.log("items available");
}
for (const item of items) {
console.log(item);
}
Functions
Functions can be written in several forms. A function declaration is
function area(width, height) {
return width * height;
}
Functions are values, so they can also be stored in variables, passed as arguments and returned from other functions.
Arrays and objects
Arrays store ordered values:
const numbers = [2, 4, 6];
Objects group named properties:
const user = { name: "Ada", active: true };
JavaScript supplies a concrete syntax for the same programming foundations as other languages while becoming especially important when code interacts with a web browser.