JS Startup

Challenges, Tips & Tricks & Tutorials

JavaScript Quiz – can isFrozen method really check freeze object

JavaScript Quiz – can isFrozen method really check freeze object

Object isFrozen Method –

Object isFrozen Method (Object.isFrozen()) is a method that checks whether the object is freeze or not. As there is Object.frozen() method is also there which can restrict the change of the value of the object key.

Object.isFrozen() method return a boolean value which means if an object is frozen then it returns true otherwise it returns false

It’s syntax looks like –

Object.isFrozen(obj)

For more detail about the javascript object isFrozen method click here.

JavaScript Question

In this javascript quiz code, you need to find out can isFrozen method really checks the frozen javascript object and what it returns.

First, we declare a variable object using let keyword and assign an javascript object to it. Which contain only one key-value pair.

let object = { name : “JS Startup” }

Now, create an another variable isFrozen and assign the value return from Object.isFrozen() method in which we pass object variable as parameter.

let isFrozen = Object.isFrozen(object);

Finally, we are checking the value of isFrozen variable using the console log And guess what should be the output will print.

Answer – false

Click To Run Code

Explanation

Now, you know the answer is false. but why it can be true. Let me explain it.

As we are checking the object variable is frozen or not. But when we assign javascript object to object variable it is in non-frozen mode.

In order to freeze an object, you need to pass javascript object to Object.freeze() method.

So, there is no Object.freeze() method is used.

At last, That’s why we get an answer “false“.

I hope you understand the concept and logic behind it.

But wait, i have something more for you –

Check out our other javascript quiz – 

  1. JavaScript Quiz – Function can be used as class using new operator
  2. JS Quiz – Reverse array element but in the same position
  3. JavaScript Quiz – filter array method based on the element size
  4. JS Quiz – copy object with JSON stringify and parse method

Conclusion

To participate in our javascript quiz or challenges, tutorial, tips & tricks make sure to join our jsstartup newsletter. So, you can able to participate in our daily challenges & learn the javascript concept.

And last but not the least, don’t forget to like, comment and share. It gives us a morale boost to remain to continue. Also, join our Facebook Page

If you have any questions, please feel free to ask me in the comment section and also let me know if you have any suggestions. As suggestions are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top
0 Shares
Share via
Copy link