Solution prevent-object-mutation.english.md (#18767)
* Update prevent-object-mutation.english.md * Improved JavaScript style
This commit is contained in:
committed by
Todd Chaffee
parent
9354cac5e6
commit
9f98cdce3b
@ -41,7 +41,7 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function freezeObj() {
|
function freezeObj() {
|
||||||
"use strict";
|
'use strict';
|
||||||
const MATH_CONSTANTS = {
|
const MATH_CONSTANTS = {
|
||||||
PI: 3.14
|
PI: 3.14
|
||||||
};
|
};
|
||||||
@ -69,6 +69,22 @@ const PI = freezeObj();
|
|||||||
<section id='solution'>
|
<section id='solution'>
|
||||||
|
|
||||||
```js
|
```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>
|
</section>
|
||||||
|
Reference in New Issue
Block a user