Menu

gitpiper

isDeepFrozen javascript Code Snippet in 2024

objectrecursionintermediate

Last Updated: 1 December 2024

Checks if an object is deeply frozen.

  • Use recursion.
  • Use Object.isFrozen() on the given object.
  • Use Object.keys(), Array.prototype.every() to check that all keys are either deeply frozen objects or non-object values.
const isDeepFrozen = obj => Object.isFrozen(obj) && Object.keys(obj).every( prop => typeof obj[prop] !== 'object' || isDeepFrozen(obj[prop]) );
const x = Object.freeze({ a: 1 }); const y = Object.freeze({ b: { c: 2 } }); isDeepFrozen(x); // true isDeepFrozen(y); // false

javascript snippet similar to isDeepFrozen For You in December 2024

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️

© 2024 GitPiper. All rights reserved

Rackpiper Technology Inc

Company

About UsBlogContact

Subscribe to our Newsletter

Subscribe to get resources directly to your inbox. You won't receive any spam! ✌️