Might come in handy for learning regular expressions or if you have a complex regular expression and you donβt know what it does (not an uncommon situation..!)
Jeff Avallone
Please open Telegram to view this post
VIEW IN TELEGRAM
π₯6β€1π1
CHALLENGE
function* generator1() {
yield 1;
yield 2;
}
function* generator2() {
yield* generator1();
yield 3;
}
const gen = generator2();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
π5β€3π€©1
What is the output?
Anonymous Quiz
68%
1, 2, 3
16%
1, 2, undefined
11%
1, undefined, 3
5%
undefined, 2, 3
π€©15π8β€7
We linked to Martin's array of creative JavaScript experiments earlier, but why not finish with one that particularly tickled us? A quine is a program that takes no input but manages to produce, as output, its own source code. Hereβs a fun JavaScript example that isnβt merely a quine, but a clock too.
Martin Kleppe
Please open Telegram to view this post
VIEW IN TELEGRAM
π₯6β€5π4π€1
CHALLENGE
function* generator() {
const value = yield 1;
yield value;
}
const gen = generator();
console.log(gen.next().value);
console.log(gen.next(2).value);
π4π€2
β€13π€7π€£2π€©1
Please open Telegram to view this post
VIEW IN TELEGRAM
β€3π2
CHALLENGE
function* generator() {
yield 1;
yield 2;
return 3;
}
const gen = generator();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
π2π₯2
π₯11β€4π4π€4
Even though Armenia π¦π² is a small country, we have a really big JavaScript community π.
There are many events related to JavaScript, and another one is happening tomorrow: JSConf Armenia 2024!
If you are in Armenia and would like to attend, just grab your tickets from the website.
There are many events related to JavaScript, and another one is happening tomorrow: JSConf Armenia 2024!
If you are in Armenia and would like to attend, just grab your tickets from the website.
β€17π7π€£7π₯4
CHALLENGE
function* generator() {
yield 1;
yield new Promise(resolve => resolve(2));
yield 3;
}
const gen = generator();
console.log(gen.next().value);
gen.next().value.then(console.log);
console.log(gen.next().value);
π5π€©2β€1
π9π₯8β€4
Josh notes that in order to truly understand promises, a fundamental part of modern JS development, we need βa surprisingly deep understanding of how JavaScript works and what its limitations areβ. Luckily, this tutorial covers all the critical context you need.
Josh W Comeau
Please open Telegram to view this post
VIEW IN TELEGRAM
π8β€2π₯2
CHALLENGE
let obj1 = { key: 'value1' };
let obj2 = { key: 'value2' };
const map = new Map();
const weakMap = new WeakMap();
map.set(obj1, 'mapValue');
weakMap.set(obj2, 'weakMapValue');
obj1 = null; // Changing reference
obj2 = null; // Changing reference
console.log(map.has(obj1));
console.log(weakMap.has(obj2));
β€7π4π₯4
π€22π₯4π€£4π3β€2
CHALLENGE
function* genFunc() {
yield Symbol('A');
yield new Function('return this')();
}
const obj = { key: genFunc().next().value };
obj.key = genFunc().next().value;
console.log(obj.key === globalThis);
π€5β€4π₯2π1
π€11β€3π€£2π1
Thereβs two parts. A library where you use generator functions to procedurally define animations, and an editor that provides a real-time preview of said animations which you can see in action here.
Motion Canvas
Please open Telegram to view this post
VIEW IN TELEGRAM
β€3π3π₯3π€£3
CHALLENGE
const secret = 'hidden';
function revealSecret() {
const secret = 'revealed';
const obj = { secret: 'object secret' };
with (obj) {
return () => secret;
}
}
const mySecret = revealSecret()();
console.log(mySecret);
π5π€5β€4π₯2
π₯9π€7π€©3β€2