TGViewer
Channel Public Channel
JavaScript

JavaScript

@javascript

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
Subscribers
31.1K
Photos
1.2K
Videos
10
Links
894

Showing posts older than #3408 · Back to latest

Older Posts 20 shown
Post #3406 2.31K
CHALLENGE

const order = [];
const log = (s) => order.push(s);

log('start');

Promise.resolve().then(() => {
log('p1');
return Promise.resolve();
}).then(() => log('p1-2'));

async function foo() {
log('foo-start');
await null;
log('foo-end');
}

foo();

Promise.resolve().then(() => log('p2'));

log('end');

setTimeout(() => console.log(order.join(' ')), 0);
  • ❤ 5
  • 🔥 1
Post #3405 2.35K
  • 🔥 4
  • ❤ 3
  • 👍 2
Post #3404 2.48K
CHALLENGE

function tag(strings, ...values) {
return strings.raw.join('|') + '=' + values.reduce((sum, v) => sum + v, 0);
}
const x = 5;
const y = 10;
console.log(tag`Sum\n${x}and${y}end`);
  • ❤ 4
  • 👍 1
Post #3403 2.58K
  • ❤ 3
  • 🔥 1
Post #3402 2.54K
CHALLENGE

const config = { retries: 0, timeout: null, name: '' };
const a = config.retries || 5;
const b = config.timeout ?? 10;
const c = config.name || 'default';
const d = config.missing?.value ?? 'fallback';
let calls = 0;
const sideEffect = () => { calls++; return true; };
const e = config.retries && sideEffect();
console.log(a, b, c, d, e, calls);
  • ❤ 4
  • 🔥 4
  • 👍 2
Post #3400 2.57K
CHALLENGE

function tag(strings, ...values) {
// strings.raw preserves literal escape sequences
const rawParts = strings.raw;
let result = rawParts.join('|');
result += '::' + values.join(',');
return result;
}

const x = 5;
const output = tag`Line1\nLine2${x}End`;
console.log(output);
  • 👍 5
  • ❤ 4
  • 🔥 2
Post #3399 2.72K
🥶 scriptc: Vercel's New TypeScript-to-Native Compiler

A new entry into the growing field of JS/TS native ahead-of-time compilers that makes the promise that "what compiles behaves byte-for-byte like Node." Static by default, but you can opt in to a --dynamic mode which embeds a JavaScript engine for runtime dynamism. GitHub repo.

Vercel Labs
  • ❤ 4
  • 👍 1
  • 🔥 1
Post #3397 2.46K
CHALLENGE

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

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

const gen = outer();
const a = gen.next().value;
const b = gen.next().value;
const c = gen.next().value;
const d = gen.next().value;
console.log(a, b, c, d);
  • 🔥 1
Post #3396 2.4K
⛽️ The Secure Way to Release an npm Package in 2026

A practical guide to publishing npm packages more safely in 2026, written by someone who's released several popular packages (like postcss and nanoid). As well as showing how to use things like staged publishing and trusted publishing, he explains why and the security benefits of doing so.

Andrey Sitnik
  • ❤ 7
  • 🔥 2
Post #3395 2.34K
  • 👍 2
  • 🔥 1
Post #3394 2.47K
CHALLENGE

class Base {
static count = 0;
static #secret;
static {
Base.#secret = 10;
Base.count += 1;
}
static getSecret() {
return Base.#secret;
}
}

class Derived extends Base {
static {
Base.count += 100;
}
}

console.log(Base.count, Derived.count, Base.getSecret());
  • ❤ 1
  • 🔥 1
Post #3393 2.34K
  • ❤ 2
  • 👍 2
Post #3392 2.39K
CHALLENGE

function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function () {
return `${this.name} makes a sound`;
};

function Dog(name) {
Animal.call(this, name);
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function () {
return `${Animal.prototype.speak.call(this)} (bark)`;
};

const d = new Dog('Rex');
console.log(
d.speak(),
d instanceof Animal,
d.constructor === Dog,
Object.getPrototypeOf(d) === Dog.prototype
);

export {};
  • 👍 3
  • ❤ 1
  • 🔥 1
Post #3391 2.31K
  • ❤ 4
  • 👍 1
Post #3390 2.56K
CHALLENGE

const source = {
_val: 1,
get val() { return this._val; }
};
const copy1 = Object.assign({}, source);
source._val = 100;
const copy2 = { ...source };
copy1._val = 999;
console.log(copy1.val, copy2.val, source.val, copy1._val);
  • ❤ 7
  • 🤣 2
  • 👍 1
  • 🔥 1
Post #3388 2.47K
CHALLENGE

const arr = [1, [2, 3], [4, [5, 6]], 7];
const a = arr.flat();
const b = arr.flat(2);
const c = arr.flatMap(x => Array.isArray(x) ? x : [x, x]);
const d = [1, 2, 3].flatMap(x => [[x]]);
console.log(JSON.stringify([a, b, c, d]));
  • ❤ 1
  • 👍 1
  • 🔥 1
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →