Home

nonenumerable

Nonenumerable describes a property that is not included when properties are enumerated. In many programming contexts, enumeration refers to iterating over an object's properties, such as with loops or methods that list keys. A nonenumerable property is one that does not appear in such enumerations, although it can still be accessed directly by name.

In JavaScript, property enumeration is controlled by the enumerable attribute of a property descriptor. By default,

Non-enumerable properties are commonly used to hide internal state, metadata, or implementation details from typical object

In summary, nonenumerable is a property characteristic that affects visibility during enumeration, not direct accessibility.

properties
created
with
simple
assignment
are
enumerable,
while
others
can
be
defined
as
non-enumerable
using
Object.defineProperty
or
Object.defineProperties
with
enumerable
set
to
false.
For
example,
defining
a
non-enumerable
property
means
it
will
not
show
up
in
for...in
loops
or
Object.keys,
and
it
will
be
skipped
by
JSON.stringify.
Nevertheless,
the
value
remains
accessible
via
obj.prop
or
obj['prop']
if
you
know
the
name,
and
it
can
be
listed
by
methods
that
expose
non-enumerable
properties,
such
as
Object.getOwnPropertyNames,
which
returns
all
own
properties
regardless
of
enumerability,
or
Object.getOwnPropertyDescriptors.
enumerations,
while
leaving
them
accessible
for
programmatic
access.
They
are
not
a
security
feature;
determined
code
can
still
read
them.
An
alternative
approach
for
true
non-visibility
is
to
use
Symbol-keyed
properties
or
private
class
fields
(introduced
in
modern
JavaScript),
which
offer
different
semantics
for
hiding
properties
from
ordinary
enumeration.