Function declarations are used to declare functions, which are blocks of code that can be called and reused multiple times. A function declaration consists of the function keyword, a name for the function, a list of parameters (which can be empty), and a body of code that will be executed when the function is called.
For example:
function addNumbers(a, b) {
return a + b;
}
Class declarations are used to declare classes, which are templates for creating objects. A class declaration consists of the class keyword, a name for the class, and a body of code that defines the properties and methods of the class.
For example:
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
sayHello() {
console.log(`Hello, my name is ${this.name}`);
}
}