Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ES6 js keywords as param exact behavior

I have a code which is expected to return 'undefined' or any error but it gives output as mentioned.

let i = (x, c) => {
    c(x);
};

i(20, (undefined) => {
    let j = undefined;
    console.log(j);
});


function y(undefined) {
    let a = undefined;
    console.log(a);
}
y(90);

How reserved words works and change behavior if used in function arguments?

like image 727
waqas jamil Avatar asked Dec 30 '25 14:12

waqas jamil


1 Answers

undefined is not a reserved word.

It is a global, readonly variable.

Nothing stops you defining another variable with the same name in a narrower scope.

like image 197
Quentin Avatar answered Jan 01 '26 03:01

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!