object-properties
    Preparing search index...

    Function defineConstant

    • Defines a non-writable and non-configurable property

      Type Parameters

      • T
      • P extends string
      • V

      Parameters

      • target: T
      • property: P

        name of the property

      • value: V

        value

      • Optionaloptions: EnumerableOptions
        • Optionalenumerable?: boolean

      Returns any

      target

      const obj = {};
      defineConstant(obj, 'PI', 3.14);
      obj.PI = 3.15; // Will not change the value
      console.log(obj.PI); // 3.14

      // With enumerable option
      defineConstant(obj, 'E', 2.718, { enumerable: true });
      console.log(Object.keys(obj)); // ['E']