FunctionDeclaration返回值疑问:Chrome DevTools与ES规范不符?
undefined? Let’s start with the two test cases you ran in Chrome DevTools:
Example 1
// First script function a(){} // Outputs: undefined
Example 2
// Second script { function a(){} } // Outputs: ƒ a(){}
As you pointed out, the ECMAScript specification clearly states that evaluating a FunctionDeclaration must return NormalCompletion(empty) — which corresponds to undefined in the console. Firefox strictly follows this rule, returning undefined for both examples. So why does Chrome behave differently?
This isn’t a bug in Chrome DevTools itself — it’s about how the V8 engine (which powers Chrome) handles block-level function declarations in non-strict mode, using an alternative semantics outlined in the spec’s Appendix B.3.3 (the note you noticed: "An alternative semantics is provided in B.3.3").
Here’s a clear breakdown:
- The core spec requires function declarations to always evaluate to
undefined, no matter where they’re placed. - Appendix B is a set of non-normative extensions for web compatibility. In non-strict mode, V8 uses this extension to treat block-internal function declarations like function expressions. When the block is evaluated as an expression (like in your second example), it returns the function object instead of
undefined. - If you switch to strict mode, Chrome will align with the core spec and match Firefox’s behavior. Try running this:
'use strict'; { function a(){} } // Outputs: undefined
To answer your question directly: No, this isn’t a Chrome DevTools issue. It’s a deliberate web-compatibility choice by the V8 engine for non-strict mode block-level functions.
内容的提问来源于stack exchange,提问作者MaximPro

