Explain the difference between Object.freeze() vs const
Explain the difference between Object.freeze() vs const
The difference between Object.freeze() and const in JavaScript pertains to the level and type of immutability they enforce.
const is a keyword introduced in ES6 (ECMAScript 2015) that creates a read-only reference to a value. When you declare a variable with const, you cannot reassign it to a different value. However, if the value assigned to a const variable is an object, you can still modify the properties of that object, even though you cannot reassign the variable itself to a different object.
Here's an example demonstrating const with an object:
const car = { color: "red" };
car.color = "blue"; // This is allowed.
car = { color: "green" }; // This will throw a TypeError because reassignment is not allowed.
Can you describe the main difference between a .forEach loop and a .map() loop and why you would pick one versus the other?
Xem chi tiếtCan you give an example for destructuring an object or an array in ES6?
Xem chi tiếtCan you give an example of a curry function and why this syntax offers an advantage?
Xem chi tiếtĐăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.