fix(learn): removed use strict from various challenges (#40321)
This commit is contained in:
@ -57,7 +57,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function myLocalScope() {
|
function myLocalScope() {
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
|
|
||||||
@ -81,7 +80,6 @@ console.log('outside myLocalScope', myVar);
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function myLocalScope() {
|
function myLocalScope() {
|
||||||
'use strict';
|
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
var myVar;
|
var myVar;
|
||||||
|
@ -54,7 +54,6 @@ console.log(printNumTwo());
|
|||||||
As you can see, <code>printNumTwo()</code> prints 3 and not 2. This is because the value assigned to <code>i</code> was updated and the <code>printNumTwo()</code> returns the global <code>i</code> and not the value <code>i</code> had when the function was created in the for loop. The <code>let</code> keyword does not follow this behavior:
|
As you can see, <code>printNumTwo()</code> prints 3 and not 2. This is because the value assigned to <code>i</code> was updated and the <code>printNumTwo()</code> returns the global <code>i</code> and not the value <code>i</code> had when the function was created in the for loop. The <code>let</code> keyword does not follow this behavior:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
'use strict';
|
|
||||||
let printNumTwo;
|
let printNumTwo;
|
||||||
for (let i = 0; i < 3; i++) {
|
for (let i = 0; i < 3; i++) {
|
||||||
if (i === 2) {
|
if (i === 2) {
|
||||||
@ -101,7 +100,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function checkScope() {
|
function checkScope() {
|
||||||
'use strict';
|
|
||||||
var i = 'function scope';
|
var i = 'function scope';
|
||||||
if (true) {
|
if (true) {
|
||||||
i = 'block scope';
|
i = 'block scope';
|
||||||
@ -123,7 +121,6 @@ function checkScope() {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function checkScope() {
|
function checkScope() {
|
||||||
'use strict';
|
|
||||||
let i = 'function scope';
|
let i = 'function scope';
|
||||||
if (true) {
|
if (true) {
|
||||||
let i = 'block scope';
|
let i = 'block scope';
|
||||||
|
@ -11,7 +11,6 @@ The keyword <code>let</code> is not the only new way to declare variables. In ES
|
|||||||
<code>const</code> has all the awesome features that <code>let</code> has, with the added bonus that variables declared using <code>const</code> are read-only. They are a constant value, which means that once a variable is assigned with <code>const</code>, it cannot be reassigned.
|
<code>const</code> has all the awesome features that <code>let</code> has, with the added bonus that variables declared using <code>const</code> are read-only. They are a constant value, which means that once a variable is assigned with <code>const</code>, it cannot be reassigned.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"use strict";
|
|
||||||
const FAV_PET = "Cats";
|
const FAV_PET = "Cats";
|
||||||
FAV_PET = "Dogs"; // returns error
|
FAV_PET = "Dogs"; // returns error
|
||||||
```
|
```
|
||||||
@ -51,7 +50,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function printManyTimes(str) {
|
function printManyTimes(str) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
|
|
||||||
@ -77,7 +75,6 @@ printManyTimes("freeCodeCamp");
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function printManyTimes(str) {
|
function printManyTimes(str) {
|
||||||
"use strict";
|
|
||||||
|
|
||||||
const SENTENCE = str + " is cool!";
|
const SENTENCE = str + " is cool!";
|
||||||
for (let i = 0; i < str.length; i+=2) {
|
for (let i = 0; i < str.length; i+=2) {
|
||||||
|
@ -12,7 +12,6 @@ Some developers prefer to assign all their variables using <code>const</code> by
|
|||||||
However, it is important to understand that objects (including arrays and functions) assigned to a variable using <code>const</code> are still mutable. Using the <code>const</code> declaration only prevents reassignment of the variable identifier.
|
However, it is important to understand that objects (including arrays and functions) assigned to a variable using <code>const</code> are still mutable. Using the <code>const</code> declaration only prevents reassignment of the variable identifier.
|
||||||
|
|
||||||
```js
|
```js
|
||||||
"use strict";
|
|
||||||
const s = [5, 6, 7];
|
const s = [5, 6, 7];
|
||||||
s = [1, 2, 3]; // throws error, trying to assign a const
|
s = [1, 2, 3]; // throws error, trying to assign a const
|
||||||
s[2] = 45; // works just as it would with an array declared with var or let
|
s[2] = 45; // works just as it would with an array declared with var or let
|
||||||
@ -53,7 +52,6 @@ tests:
|
|||||||
```js
|
```js
|
||||||
const s = [5, 7, 2];
|
const s = [5, 7, 2];
|
||||||
function editInPlace() {
|
function editInPlace() {
|
||||||
'use strict';
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
|
|
||||||
// Using s = [2, 5, 7] would be invalid
|
// Using s = [2, 5, 7] would be invalid
|
||||||
@ -75,7 +73,6 @@ editInPlace();
|
|||||||
```js
|
```js
|
||||||
const s = [5, 7, 2];
|
const s = [5, 7, 2];
|
||||||
function editInPlace() {
|
function editInPlace() {
|
||||||
'use strict';
|
|
||||||
s[0] = 2;
|
s[0] = 2;
|
||||||
s[1] = 5;
|
s[1] = 5;
|
||||||
s[2] = 7;
|
s[2] = 7;
|
||||||
|
@ -54,7 +54,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function freezeObj() {
|
function freezeObj() {
|
||||||
'use strict';
|
|
||||||
const MATH_CONSTANTS = {
|
const MATH_CONSTANTS = {
|
||||||
PI: 3.14
|
PI: 3.14
|
||||||
};
|
};
|
||||||
@ -83,7 +82,6 @@ const PI = freezeObj();
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
function freezeObj() {
|
function freezeObj() {
|
||||||
'use strict';
|
|
||||||
const MATH_CONSTANTS = {
|
const MATH_CONSTANTS = {
|
||||||
PI: 3.14
|
PI: 3.14
|
||||||
};
|
};
|
||||||
|
@ -67,7 +67,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
var magic = function() {
|
var magic = function() {
|
||||||
"use strict";
|
|
||||||
return new Date();
|
return new Date();
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
@ -83,7 +82,6 @@ var magic = function() {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const magic = () => {
|
const magic = () => {
|
||||||
"use strict";
|
|
||||||
return new Date();
|
return new Date();
|
||||||
};
|
};
|
||||||
```
|
```
|
||||||
|
@ -51,7 +51,6 @@ tests:
|
|||||||
```js
|
```js
|
||||||
const source = [1,2,3,4,5,6,7,8,9,10];
|
const source = [1,2,3,4,5,6,7,8,9,10];
|
||||||
function removeFirstTwo(list) {
|
function removeFirstTwo(list) {
|
||||||
"use strict";
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
const arr = list; // Change this line
|
const arr = list; // Change this line
|
||||||
// Only change code above this line
|
// Only change code above this line
|
||||||
@ -73,7 +72,6 @@ const arr = removeFirstTwo(source);
|
|||||||
```js
|
```js
|
||||||
const source = [1,2,3,4,5,6,7,8,9,10];
|
const source = [1,2,3,4,5,6,7,8,9,10];
|
||||||
function removeFirstTwo(list) {
|
function removeFirstTwo(list) {
|
||||||
"use strict";
|
|
||||||
const [, , ...arr] = list;
|
const [, , ...arr] = list;
|
||||||
return arr;
|
return arr;
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
var myConcat = function(arr1, arr2) {
|
var myConcat = function(arr1, arr2) {
|
||||||
"use strict";
|
|
||||||
return arr1.concat(arr2);
|
return arr1.concat(arr2);
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -82,7 +81,6 @@ console.log(myConcat([1, 2], [3, 4, 5]));
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const myConcat = (arr1, arr2) => {
|
const myConcat = (arr1, arr2) => {
|
||||||
"use strict";
|
|
||||||
return arr1.concat(arr2);
|
return arr1.concat(arr2);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,7 +53,6 @@ tests:
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const createPerson = (name, age, gender) => {
|
const createPerson = (name, age, gender) => {
|
||||||
"use strict";
|
|
||||||
// Only change code below this line
|
// Only change code below this line
|
||||||
return {
|
return {
|
||||||
name: name,
|
name: name,
|
||||||
@ -75,7 +74,6 @@ const createPerson = (name, age, gender) => {
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const createPerson = (name, age, gender) => {
|
const createPerson = (name, age, gender) => {
|
||||||
"use strict";
|
|
||||||
return {
|
return {
|
||||||
name,
|
name,
|
||||||
age,
|
age,
|
||||||
|
Reference in New Issue
Block a user