Solution prevent-object-mutation.english.md (#18767)
* Update prevent-object-mutation.english.md * Improved JavaScript stylepull/19395/head
parent
9354cac5e6
commit
9f98cdce3b
|
@ -41,7 +41,7 @@ tests:
|
|||
|
||||
```js
|
||||
function freezeObj() {
|
||||
"use strict";
|
||||
'use strict';
|
||||
const MATH_CONSTANTS = {
|
||||
PI: 3.14
|
||||
};
|
||||
|
@ -69,6 +69,22 @@ const PI = freezeObj();
|
|||
<section id='solution'>
|
||||
|
||||
```js
|
||||
// solution required
|
||||
function freezeObj() {
|
||||
'use strict';
|
||||
const MATH_CONSTANTS = {
|
||||
PI: 3.14
|
||||
};
|
||||
// change code below this line
|
||||
Object.freeze(MATH_CONSTANTS);
|
||||
|
||||
// change code above this line
|
||||
try {
|
||||
MATH_CONSTANTS.PI = 99;
|
||||
} catch( ex ) {
|
||||
console.log(ex);
|
||||
}
|
||||
return MATH_CONSTANTS.PI;
|
||||
}
|
||||
const PI = freezeObj();
|
||||
```
|
||||
</section>
|
||||
|
|
Loading…
Reference in New Issue