JavaScript
31K subscribers
1.23K photos
10 videos
33 files
899 links
A resourceful newsletter featuring the latest and most important news, articles, books and updates in the world of #javascript 🚀 Don't miss our Quizzes!

Let's chat: @nairihar
Download Telegram
🎵 Tonny Espeset has recreated the '80s hit Take on Me by A-ha in pure JavaScript (along with synthesized vocals!), running through the always-entertaining Dittytoy online JavaScript music playground.
Please open Telegram to view this post
VIEW IN TELEGRAM
❤8
CHALLENGE

async function* gen() {
const x = yield 1;
const y = yield x + 1;
return x + y;
}

async function main() {
const it = gen();
const a = await it.next();
const b = await it.next(10);
const c = await it.next(20);
console.log(`${a.value} ${b.value} ${c.value} ${c.done}`);
}

main();
👍2
CHALLENGE

const sym1 = Symbol('id');
const sym2 = Symbol('id');

const obj = {
[sym1]: 'first',
[sym2]: 'second',
regular: 'value'
};

const s = Symbol.for('shared');
const s2 = Symbol.for('shared');

console.log(
sym1 === sym2,
Object.keys(obj).length,
Reflect.ownKeys(obj).length,
s === s2,
sym1.toString()
);
❤1
CHALLENGE

function tag(strings, ...values) {
return strings.raw.join('|') + '::' + values.join(',');
}

const a = 5, b = 10;
console.log(tag`Sum:\n${a + b} End`);
CHALLENGE

const a = -7 % 3;
const b = 7 % -3;
const c = 2 ** 3 ** 2;
const d = (2 ** 3) ** 2;
const e = 0.1 + 0.2;
console.log(a, b, c, d, e);
CHALLENGE

async function main() {
const settled = await Promise.allSettled([
Promise.resolve(1),
Promise.reject('err'),
]);
const statuses = settled.map(s => s.status).join(',');

let anyResult;
try {
await Promise.any([Promise.reject('a'), Promise.reject('b')]);
} catch (err) {
anyResult = `${err.name}:${err.errors.join(',')}`;
}

console.log(statuses, anyResult);
}

main();