JavaScript
31K subscribers
1.23K photos
10 videos
33 files
904 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
🤣2❤1
CHALLENGE

const source = {
count: 0,
get value() {
this.count++;
return this.count;
}
};

const { value, ...rest } = source;
const spread = { ...source };

console.log(value, spread.value, source.count, JSON.stringify(rest));
❤2🔥1🤣1
CHALLENGE

const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);
const addOne = x => x + 1;
const double = x => x * 2;
const square = x => x * x;
console.log(compose(square, double, addOne)(3), pipe(square, double, addOne)(3));
🤩1
What is the output?
Anonymous Quiz
14%
19 19
53%
64 19
22%
64 64
11%
19 64
CHALLENGE

let i = 0;
const key = () => `k${i++}`;
const obj = { [key()]: 1, [key()]: 2, [key()]: 3 };
const sym = Symbol('x');
const keyObj = { toString() { return 'dyn'; } };
const obj2 = {
[sym]: 'secret',
[`a${1 + 1}`]: 'computed',
['a' + 2]: 'overwritten',
[keyObj]: 'fromObj'
};
console.log(`${Object.keys(obj).join(',')} ${obj2.a2} ${obj2.dyn} ${obj2[sym]}`);
👍3❤1
CHALLENGE

const memoize = (fn) => {
const cache = new Map();
return (...args) => {
const key = JSON.stringify(args);
if (cache.has(key)) return cache.get(key);
const result = fn(...args);
cache.set(key, result);
return result;
};
};

let calls = 0;
const square = memoize((x) => {
calls++;
return x * x;
});

console.log(square(4), square(4), square(-4), calls);
❤2
❤2
CHALLENGE

const handler = {
get(target, prop, receiver) {
if (!(prop in target)) {
return `no ${String(prop)}`;
}
return Reflect.get(target, prop, receiver);
},
set(target, prop, value) {
if (typeof value === 'number' && value < 0) {
throw new RangeError('negative');
}
return Reflect.set(target, prop, value);
}
};

const obj = new Proxy({ a: 1, b: 2 }, handler);
obj.c = 10;
console.log(obj.a, obj.c, obj.missing, obj.hasOwnProperty('a'));
❤2🔥2👍1
CHALLENGE

let counter = 0;
const state = {
get value() {
counter++;
return counter % 3 === 0 ? null : counter;
}
};
let result;
result ??= state.value;
result ??= state.value;
result ??= state.value;
result ??= state.value;
console.log(result, counter);
❤1
What is the output?
Anonymous Quiz
23%
3 3
41%
null 4
24%
1 1
13%
1 4
🔥3❤1
👀 tsrs: Cloudflare and VoidZero's Rust Port of TypeScript

A Rust port of the Go-based TypeScript 7 compiler, built with some input from the TypeScript team and heading into Oxc. Benchmarks claim up to 8x the speed of TypeScript 7.0 and it runs in WebAssembly. Experimental, but npx tsrs works.

Chen, Mitropoulos and Nakazawa (Cloudflare / VoidZero)
Please open Telegram to view this post
VIEW IN TELEGRAM
❤4👍3🔥1
CHALLENGE

const s = "JavaScript";
const str = new String(s);
console.log(str === s, str == s, typeof str, str.at(-1), s.at(-1));
❤2
📍 Maplair: A Batteries-Included, Tree-Shakeable Fork of Leaflet

Still in alpha since last year, one of Leaflet's contributors has forked it, rolling in the 2.0 work plus rotation, fullscreen, search, heatmaps and more – all tree-shakeable.

Simon Legner
Please open Telegram to view this post
VIEW IN TELEGRAM
❤1🔥1
CHALLENGE

const a = [] + [];
const b = [] + {};
const c = {} + [];
const d = 1 + "1" - 1;
const e = "5" - "2" + "3";
const f = [1, 2] == "1,2";
console.log(a, b, c, d, e, f);
🔥1🤩1
🖼️ JPEG XL: The modern image format is now supported by all major browsers, with Firefox 158 the latest to enable it by default. Jake Archibald pits it against AVIF in this extensive review. What I find amazing is what it's able to render in under 100 bytes.
Please open Telegram to view this post
VIEW IN TELEGRAM
❤2👍2🔥1