Answer the question
In order to leave comments, you need to log in
Different javascript interpreter behavior in Chrome and Firefox?
A colleague accidentally stumbled upon the following difference in how browsers work. The latest versions are being used.
The code:
<html>
<head>
<script>
function test() {
functionExpressionOrFunctionDeclaration();
if (true) {
function functionExpressionOrFunctionDeclaration() {
console.log('run');
}
}
}
test();
</script>
</head>
</html>
"A function declaration is very easily (and often unintentionally) turned into a function expression."
Answer the question
In order to leave comments, you need to log in
Here it is broken down in detail.
dmitrysoshnikov.com/ecmascript/en-chapter-5-functi...
Formally, both are right, because this situation is not defined by the standard
I am on the side of FF in the issue of the impossibility of the appearance of FD in the block of instructions. If it's called a statement block, then the declaration doesn't belong there.
@Lynn gave the correct link to Dmitry Soshnikov, only I can't select his comment as the correct answer.
Here for similar things also there is "use strict". With it, you will get a "SyntaxError" since a function declaration cannot be in statement blocks.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question