JavaScript variables are used to store data values. They can be changed during the execution of a program.
let x = 10;
Constants are like variables, but they cannot be changed once they are declared.
const pi = 3.14;
Conditional statements, like if, else, and else if, allow you to make decisions in your code.
if (x > 10) { /* do something */ }
Loops are used to repeatedly execute a block of code. Common loop types include for, while, and do...while.
for (let i = 0; i < 5; i++) { /* do something */ }
Functions are blocks of code that can be called to perform a specific task. They can return values.
function greet(name) { return 'Hello, ' + name; }
Arrays are used to store multiple values in a single variable. They are indexed and can be modified.
let fruits = ['apple', 'banana', 'cherry'];
Strings are sequences of characters and are used for storing and manipulating text.
let message = 'Hello, World!';
Objects are used to store collections of key-value pairs. They are versatile data structures.
let person = { firstName: 'John', lastName: 'Doe' };
ES6 introduced many new features to JavaScript, including arrow functions, template literals, and destructuring.
const greet = (name) => `Hello, ${name}`;