function add(a, b) {
    return a + b;
};

add(1, 2); // 3
const add = function(a, b) {
    return a + b;
};

add(1, 2); // 3
const add = (a, b) => {
    return a + b;
};

add(1, 2); // 3
// Parentheses are optional when there is only one parameter.
const func = param => { ... }; // Parentheses omitted

// This is equivalent to:
const func = (param) => { ... }; // Parentheses included
const add = (a, b) => a + b; // When omitting <code>return</code>, curly braces must be omitted as well.

// This is equivalent to:
const add = (a, b) => { return a + b; };
const add = (a, b) => {
    const sum = a + b;
    console.log("Sum:", sum);

    // <code>return</code> cannot be omitted here.
    return sum;
};

const result = add(3, 5);
console.log("Result:", result); // Output: Sum: 8, Result: 8
// Incorrect usage: duplicate parameter names
const multiply = (x, y, x) => {
    return x * y;
};
const Person = (name) => {
    this.name = name;
};

const john = new Person("John"); // Error: Person is not a constructor
const Person = (name) => {
    this.name = name;
};

console.log(Person.hasOwnProperty("prototype")); // false
<!DOCTYPE html>
<html>
    <head>
        <title>Event Listener Example</title>
    </head>
    <body>
        <button id="myButton">Click Me</button>
        <script src="event.js"></script>
    </body>
</html>
// event.js
const myButton = document.getElementById('myButton');

// Event handler using a regular function
myButton.addEventListener("click", function() {
    console.log("Clicked using normal function. This: " + this.textContent);
});

// Event handler using an arrow function
myButton.addEventListener("click", () => {
    console.log("Clicked using arrow function. This text: " + this.textContent);
});
function sumWithArguments() {
    let sum = 0;

    for (let i = 0; i < arguments.length; i++) {
        sum += arguments[i];
    }

    return sum;
}

const sumWithArrow = () => {
    let sum = 0;

    for (let i = 0; i < arguments.length; i++) {
        sum += arguments[i]; // Error: arguments is not defined
    }

    return sum;
}

console.log(sumWithArguments(1, 2, 3, 4, 5)); // Output: 15
console.log(sumWithArrow(1, 2, 3, 4, 5)); // Error: arguments is not defined
const myObj = {
    name: "John Doe",

    func: function() {
        console.log(this.name); // Output: "John Doe"

        // Using a regular function
        setTimeout(function() {
            console.log(this);           // Output: window (or global object in Node.js)
            console.log(this.name);      // Output: undefined
        }, 1000);

        // Using bind() with a regular function
        setTimeout(function() {
            console.log(this);           // Output: myObj
            console.log(this.name);      // Output: "John Doe"
        }.bind(this), 1000);
    },

    arrow_func: function() {
        console.log(this.name); // Output: "John Doe"

        // Using an arrow function
        setTimeout(() => {
            console.log(this);           // Output: myObj
            console.log(this.name);      // Output: "John Doe"
        }, 1000);
    }
};

myObj.func();
myObj.arrow_func();