Files
Randell Dawson 1494a50123 fix(guide): restructure curriculum guide articles (#36501)
* fix: restructure certifications guide articles
* fix: added 3 dashes line before prob expl
* fix: added 3 dashes line before hints
* fix: added 3 dashes line before solutions
2019-07-24 13:29:27 +05:30

1.1 KiB

title
title
Mutate an Array Declared with const

Mutate an Array Declared with const


Problem Explanation

Reassign the values of the const variable s using various element assignment.


Hints

Hint 1

  • You can change array values on const like you can with var or let.

Hint 1

  • To access array value use array[index]

Solutions

Solution 1 (Click to Show/Hide)
const s = [5, 7, 2];
function editInPlace() {
  "use strict";
  s[0] = 2;
  s[1] = 5;
  s[2] = 7;
}
editInPlace();

Code Explanation

Trying to reassign a read-only const variable will throw an error, but by using various element assignment you can access and change the value of an array just like you would with let or var.