docta_faustus docta_faustus - 6 months ago 21
Javascript Question

Why don't functions have a [[Value]] attribute?

It seems that functions are missing the [[Value]] attribute property which is present on other object properties:

function a() {
console.log('Hello World');

var descriptor = Object.getOwnPropertyDescriptor(window, 'a');

// descriptor contains:

Object {writable: true, enumerable: true, configurable: false}

Compared to:

var person = {
age: 1

var descriptor2 = Object.getOwnPropertyDescriptor(person, 'age');

// descriptor2 contains:

Object {value: 1, writable: true, enumerable: true, configurable: true}

Why isn't there a [[Value]] attribute like most regular object properties? I would expect it would contain the actual function body code but it looks like it doesn't ever exist for functions?


Whether the value of the property is a function or a number doesn't really matter to the descriptor / property. And the descriptor does have a value property: enter image description here

How the console works is not standardized, so why something is or isn't displayed is implementation dependent.

Do not blindly trust the console, verify your assumptions with code.