const user = {
username: "hitesh",
price: 999,
welcomeMessage: function() {
console.log(`${this.username} , welcome to website`);
console.log(this);
}
}
Here this refers to Current context
console.log(this); //In node env return {}
console.log(this); //In Browser return Window{}
thisnot works inisde 01_functions/code>
Arrow Function
const chai = () => {
let username = "hitesh"
console.log(this);
}
Console Output:
{}
const addTwo = (num1, num2) => num1 + num2
const addTwo = (num1, num2) => num1 + num2
const addTwo = (num1, num2) => ( num1 + num2 )
Both will return same result.
const addTwo = (num1, num2) => ({username: "hitesh"})
Here, the parentheses () around { username: "hitesh" } are used to indicate that this is an object literal and not a block of code.