You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
const initialScores = [0, 0];
// player a, player b, total games played
const state = [5, 2, 7];
// reset scores only
Object.assign(state , initialScores);
// state = [0, 0, 7];
{} can be used to create local scopes anywhere
const minMax = function (numbers) {
const results = [];
// variables localResult does not clash,
// independent blocks are used
{
const localResult = Math.min(...numbers);
results.push(localResult);
}
{
const localResult = Math.max(...numbers);
results.push(localResult);
}
return results;
};
Array destructuring syntax can be used to swap variables
let a = 5;
let b = 2;
[a, b] = [b, a];
new Set to remove duplicates from an array
let a = [5, 4, 4, 4, 3];
a = [...(new Set(a))];
Object.seal to ensure that a passed object does not exceed an interface