| 1. |
Explain Constants In Es6? |
|
Answer» Constants also are known as immutable variables are a special type of variables whose content is not changed. In Es6 a constant is defined using const keyword. Constants in Es6 enable protection to overwrite a variable value, improve performance and helps PROGRAMMERS to write readable and CLEANER CODE. Example: In Es6 const WEBSITE_URL = "http://www.abc.com"; WEBSITE_URL="new url"; // generate an error; console.log (WEBSITE_URL); In prior version of Es6 // and only in global CONTEXT and not in a block scope Object.defineProperty(type of global === "object" ? global : window, "WEBSITE_URL", { value: "http://www.abc.com", enumerable: TRUE, writable: false, configurable: false }); console.log (WEBSITE_URL); Constants also are known as immutable variables are a special type of variables whose content is not changed. In Es6 a constant is defined using const keyword. Constants in Es6 enable protection to overwrite a variable value, improve performance and helps programmers to write readable and cleaner code. Example: In Es6 const WEBSITE_URL = "http://www.abc.com"; WEBSITE_URL="new url"; // generate an error; console.log (WEBSITE_URL); In prior version of Es6 // and only in global context and not in a block scope Object.defineProperty(type of global === "object" ? global : window, "WEBSITE_URL", { value: "http://www.abc.com", enumerable: true, writable: false, configurable: false }); console.log (WEBSITE_URL); |
|