special function
debounce data

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]];
}
7 ways to flip two varibles
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]; -------
b = [a, a = b][0]; a = b + (b = a, "");
[a,b] = [b,a];
generator
Generator function
function* generator(i) { yield i; yield i + 10; }
GeneratorFunction
Object.getPrototypeOf(function*(){}).constructor
function* expression
const foo = function*() { yield 'a'; yield 'b'; yield 'c'; };
Returns a value yielded by the yield
expression.
Returns the given value and finishes the generator.
Throws an error to a generator (also finishes the generator, unless caught from within that generator).
function* infinite() {
let index = 0;
while (true) {
yield index++;
}
}
const generator = infinite(); // "Generator { }"
console.log(generator.next().value); // 0
console.log(generator.next().value); // 1
Last updated
Was this helpful?