There is a JS problem. I can't figure out why. Looking for answers.

var x = 1;
if (function f(){}) {
    x += typeof f;
}
console.log(x);

"1undefined"
Jan.10,2022

if(/*expression*/)

expression, if (function f () {}) function f () {} in is a function expression with a name , not a function declaration statement

clipboard.png

f

clipboard.png

function f(){}()

clipboard.png

() (),()

clipboard.png

because return is also followed by an expression, function f () {} is considered an expression, so no error is reported when executed directly.

Expressions are also accepted only in

if , so the variable f

is not declared.

to sum up, there are two test points:
1 expression if (/ expression /) receives expressions instead of function declarations.
2, the function name cannot be taken externally in the function expression (because it is optional). The function name is required in the function declaration and optional in the function expression.
so the question just now can't get the f. / p > in if ().

Menu