I would like to know how to put a default value for the constant b
, I have to do an exercise 'deconstructing' arrays, but b
is already assigned as constant and I do not know how to make it worth 2 without touching this line of code. I tried let [,b] = [a,b,c]
but obviously it does not go and I do not know how it is.
You must pass this testing with Jasmine:
describe('destructuring can also have default values. ', () => {
it('for a missing value', () => {
const [a,b,c] = [1,,3];
expect(b).toEqual(2);
});
});
// load jasmine htmlReporter
(function() {
var env = jasmine.getEnv();
env.addReporter(new jasmine.HtmlReporter());
env.execute();
}());
<link rel="stylesheet" href="https://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.css" />
<script src="https://cdn.jsdelivr.net/jasmine/1.3.1/jasmine.js"></script>
<script src="https://cdn.jsdelivr.net/jasmine/1.3.1/jasmine-html.js"></script>