From e9651c6afe9c9d327c0604f8affa766168095c66 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Sun, 24 Sep 2023 21:44:33 +0600 Subject: [PATCH] wip: add more questions --- .../javascript/content/immutable-object.md | 12 ++++++++++++ src/data/question-groups/javascript/javascript.md | 5 +++++ 2 files changed, 17 insertions(+) create mode 100644 src/data/question-groups/javascript/content/immutable-object.md diff --git a/src/data/question-groups/javascript/content/immutable-object.md b/src/data/question-groups/javascript/content/immutable-object.md new file mode 100644 index 000000000..81ddb9e2c --- /dev/null +++ b/src/data/question-groups/javascript/content/immutable-object.md @@ -0,0 +1,12 @@ +To make an object immutable, you can use `Object.freeze()` method. It prevents the modification of existing property values and prevents the addition of new properties. + +```js +const roadmap = { + name: 'JavaScript', +}; + +Object.freeze(roadmap); + +roadmap.name = 'JavaScript Roadmap'; // throws an error in strict mode +console.log(roadmap.name); // JavaScript +``` diff --git a/src/data/question-groups/javascript/javascript.md b/src/data/question-groups/javascript/javascript.md index 1b1766fc4..3aeee808f 100644 --- a/src/data/question-groups/javascript/javascript.md +++ b/src/data/question-groups/javascript/javascript.md @@ -206,4 +206,9 @@ questions: topics: - 'Core' - 'Advanced' + - question: How to make an Object immutable in JavaScript? + answer: immutable-object.md + topics: + - 'Core' + - 'Advanced' ---