Create an arrow function named greet that takes a parameter name and returns the string "Hello, " followed by the value of name. log the output of the function to the console using console.log(greet());
ES6 introduced several new features to make JavaScript cleaner and more powerful.
let
allows you to declare block-scoped variables.const
declares block-scoped constants that cannot be reassigned.
let count = 10;
count = 15; // allowed
const name = "Alice";
// name = "Bob"; // Error: Assignment to constant variable.
Arrow functions provide a concise syntax for writing functions.
// Traditional function
function add(a, b) {
return a + b;
}
// Arrow function
const add = (a, b) => a + b;
Arrow functions also do not have their own this
context, which changes how this
behaves inside them.