What is an intermediate value?

An “intermediate value” is just a value that’s produced inside an expression that isn’t the final value of the expression. In a = (b * c) + d the result of b * c is an intermediate value in the right-hand-side expression.

Yes, in this specific case, the error message could say “(anonymous function) is not a function or its return value is not iterable”. Not all intermediate values are anonymous functions, though. The implementers of V8 just chose to use a generic error message. (SpiderMonkey [in Firefox] uses the same terminology, though a different message.)

Is there an official definition to this?

The specification uses the term “intermediate result” here, to mean essentially the same thing as “intermediate value” (to my eye):

6.2 ECMAScript Specification Types

A specification type corresponds to meta-values that are used within algorithms to describe the semantics of ECMAScript language constructs and ECMAScript language types. The specification types include Reference, List, Completion, Property Descriptor, Lexical Environment, Environment Record, and Data Block. Specification type values are specification artefacts that do not necessarily correspond to any specific entity within an ECMAScript implementation. Specification type values may be used to describe intermediate results of ECMAScript expression evaluation but such values cannot be stored as properties of objects or values of ECMAScript language variables.

(my emphasis)


Note that your code samples are not identical other than giving the function a name. One of them attempts to iterate the value 7. The other attempts to iterate the value undefined. It doesn’t matter to the error message from V8 but it did for SpiderMonkey. Let’s compare apples with apples, remove irrelevancies, and declare our variable:

"use strict";

var myFunc;

try {
  [myFunc] = function(){
    return 7;
  }();
} catch (e) {
  console.error(e.message);
}

try {
  [myFunc] = function hi(){
    return 7;
  }();
} catch (e) {
  console.error(e.message);
}

try {
  function hi(){
    return 7;
  }
  [myFunc] = hi();
} catch (e) {
  console.error(e.message);
}

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)