JavaScript
31.1K subscribers
1.23K photos
10 videos
33 files
895 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
CHALLENGE

function* inner() {
yield 1;
yield 2;
return 100;
}

function* outer() {
const result = yield* inner();
yield result;
yield 3;
}

const it = outer();
console.log(it.next().value, it.next().value, it.next().value, it.next().value);
❤5👍2🤔1
❤1
🤩 tinyjs: Build JavaScript Desktop Apps in <10MB

I built an app with this and was impressed. You get a txiki.js-powered backend with full system access (including FFI!), native webview rendering, and tiny macOS, Linux, and Windows builds. It even makes it easy to sign/notarize the final app.

Tarwin Stroh-Spijer
Please open Telegram to view this post
VIEW IN TELEGRAM
❤6👍2
CHALLENGE

class Base {
static count = 0;
static increment() {
this.count++;
return this.count;
}
}

class Derived extends Base {
static count = 10;
}

console.log(Base.increment(), Derived.increment(), Base.count, Derived.count);
❤1
❤2🔥2👍1
CHALLENGE

let counter = 0;
const mod = {
get counter() { return counter; },
increment() { counter++; }
};

const { counter: snapshotCounter } = mod;
mod.increment();
mod.increment();

console.log(snapshotCounter, mod.counter, counter);
❤2🔥2
What is the output?
Anonymous Quiz
30%
0 2 2
28%
0 0 0
22%
0 1 2
20%
2 2 2
❤1🔥1🤣1
CHALLENGE

const obj = {
value: 42,
getValue() { return this?.value; },
getValueArrow: () => this?.value
};
const { getValue, getValueArrow } = obj;
console.log(obj.getValue(), getValue(), obj.getValueArrow(), getValueArrow());
❤1
CHALLENGE

class Base {
value = 10;
getValue = () => this.value;
constructor() {
this.value = 20;
}
}

class Derived extends Base {
value = 30;
}

const d = new Derived();
console.log(d.getValue(), d.value);
❤3🔥2
What is the output?
Anonymous Quiz
22%
10 30
39%
20 30
17%
20 20
21%
30 30
CHALLENGE

let order = [];
function a() {
try {
return 'try';
} finally {
order.push('a-finally');
return 'a-final-return';
}
}
function b() {
try {
throw new Error('x');
} catch (e) {
order.push('b-catch');
return 'b-catch-return';
} finally {
order.push('b-finally');
}
}
console.log(a(), b(), order.join(','));
❤1🔥1
CHALLENGE

const order = [];
order.push('start');
setTimeout(() => { order.push('timeout'); console.log(order.join(',')); }, 0);
Promise.resolve().then(() => order.push('promise1'));
async function foo() {
order.push('foo start');
await null;
order.push('foo end');
}
foo();
Promise.resolve().then(() => order.push('promise2'));
order.push('end');
❤2🔥1
CHALLENGE

const message = 'a😀bc';
const codePoints = [...message];
const combined = {
raw: message.length,
points: codePoints.length,
second: codePoints[1]
};
console.log(combined.raw, combined.points, combined.second);
❤2
CHALLENGE

class Counter {
#count = 0;
static #instances = 0;
constructor() { Counter.#instances++; }
#increment() { this.#count++; }
incrementAndGet() {
this.#increment();
return this.#count;
}
static get total() { return Counter.#instances; }
}

class SpecialCounter extends Counter {
incrementAndGet() {
return super.incrementAndGet() * 2;
}
}

const c1 = new Counter();
const c2 = new SpecialCounter();
console.log(`${c1.incrementAndGet()} ${c2.incrementAndGet()} ${Counter.total}`);
What is the output?
Anonymous Quiz
14%
1 2 1
48%
1 4 2
21%
2 2 2
17%
1 2 2
❤1