special function
Last updated
Was this helpful?
Last updated
Was this helpful?
Operation DOM:
let temp = document.getElementsByTagName("a"); for (let i of temp) { console.log(i.innerHTML); }
Random array
for (let i = temp.length - 1; i >= 0; i--) {
let j = Math.floor(Math.random() * (i + 1));
[temp[i], temp[j]] = [temp[j], temp[i]];
}
a = "hello", b = "bye";
var c = a; a = b; b = c;
a = a + b; b = a - b; a = a - b; -------- a = a - b; b = a + b; a = b - a;
a ^= b; b ^= a; a ^= b; a = (b^=a^=b)^a;
a = {a:b,b:a}; b = a.b; a = a.a;
a = [a,b]; b = a[0]; a = a[1];
a = [b,b=a][0]; -------
[a,b] = [b,a];
Generator function
function* generator(i) { yield i; yield i + 10; }
const foo = function*() { yield 'a'; yield 'b'; yield 'c'; };
Returns the given value and finishes the generator.
Throws an error to a generator (also finishes the generator, unless caught from within that generator).
Returns a value yielded by the expression.