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
895

Showing posts older than #2962 · Back to latest

Older Posts 20 shown
Post #2961 3.51K
CHALLENGE

const user = {
profile: {
settings: {
theme: 'dark',
notifications: null
}
}
};

const getNotificationSound = (user) => {
return user?.profile?.settings?.notifications?.sound ?? 'default';
};

console.log(getNotificationSound(user));
console.log(getNotificationSound(null));
console.log(getNotificationSound({ profile: {} }));
  • ❤ 6
  • 👍 6
  • 🔥 3
Post #2960 3.36K
🌲 Improving Single Executable Application Building in Node

First introduced two years ago, Node has a (still experimental) feature to build single executable applications that can be deployed to machines that don’t have Node installed. This week’s Node.js 25.5 release, with its --build-sea flag, moves the final injection step into Node itself, eliminating the need for external tooling and turning what was a multi-step, low-level process into a single command.

Joyee Cheung
  • 👍 8
  • ❤ 6
  • 🔥 2
Post #2959 3.19K
  • 🔥 4
  • 👍 3
  • ❤ 2
  • 🤔 2
Post #2958 3.31K
CHALLENGE

const nums = [1, 2, 3];
const obj = { a: 1, b: 2 };
const newObj = { ...obj, b: 3, ...obj };

const arr1 = [4, 5];
const arr2 = [6, 7];
const combined = [...nums, ...arr1, ...arr2];

const [first, ...rest] = combined;
const { a, ...remaining } = newObj;

console.log(newObj.b);
console.log(rest.length);
console.log(remaining.b);
  • 👍 6
  • 🔥 4
  • ❤ 2
Post #2956 3.49K
  • ❤ 2
  • 🤔 2
  • 🔥 1
Post #2955 3.25K
CHALLENGE

console.log('start');

Promise.resolve().then(() => {
console.log('promise 1');
});

setTimeout(() => {
console.log('timeout');
}, 0);

Promise.resolve().then(() => {
console.log('promise 2');
}).then(() => {
console.log('promise 3');
});

console.log('end');
  • ❤ 6
  • 👍 3
  • 🔥 3
Post #2954 3.23K
🤔 Porting 100k Lines from TypeScript to Rust in a Month

A prolific JavaScript developer ported a Pokémon battle simulator to Rust and shares his experiences and techniques used to work around issues where Claude Code would get bogged down in such a large task. He notes “LLM-based coding agents are such a great new tool” but require “engineering expertise and constant babysitting”.

Christopher Chedeau
  • ❤ 6
  • 👍 5
  • 🔥 4
Post #2953 3.29K
  • ❤ 5
  • 🤔 5
  • 👍 2
Post #2952 3.34K
CHALLENGE

const wm = new WeakMap();
let obj1 = { name: 'John' };
let obj2 = { name: 'Jane' };

wm.set(obj1, 'developer');
wm.set(obj2, 'designer');

console.log(wm.get(obj1));
console.log(wm.has(obj2));

obj1 = null;
console.log(wm.get(obj1));

const normalObj = {};
try {
wm.set('string', 'value');
} catch (e) {
console.log('error');
}
  • 👍 6
  • 🔥 2
Post #2949 3.31K
CHALLENGE

const x = 15;
const y = 10;
const z = 3;

const result1 = x & y;
const result2 = x | y;
const result3 = x ^ y;
const result4 = ~x;
const result5 = y << z;
const result6 = y >> 1;

console.log(`${result1},${result2},${result3},${result4},${result5},${result6}`);
  • 🔥 4
  • ❤ 3
  • 👍 2
Post #2947 3.35K
CHALLENGE

const obj = {
data: ['x', 'y', 'z'],
*[Symbol.iterator]() {
for (let i = this.data.length - 1; i >= 0; i--) {
yield this.data[i].toUpperCase();
}
}
};

const result = [];
for (const item of obj) {
result.push(item);
if (result.length === 2) break;
}

console.log(result.join('-'));
  • ❤ 13
  • 👍 3
  • 🔥 1
Post #2946 3.31K
  • 👍 7
  • ❤ 1
Post #2945 3.39K
CHALLENGE

class EventEmitter {
constructor() {
this.events = new Map();
}

on(event, callback) {
if (!this.events.has(event)) {
this.events.set(event, []);
}
this.events.get(event).push(callback);
return this;
}

emit(event, ...args) {
const callbacks = this.events.get(event);
if (callbacks) {
callbacks.forEach(cb => cb(...args));
}
return this;
}
}

const emitter = new EventEmitter();
emitter.on('test', x => console.log(x * 2))
.on('test', x => console.log(x + 10))
.emit('test', 5);
  • ❤ 6
  • 👍 3
Post #2944 3.09K
  • 🤔 5
  • 🔥 3
  • ❤ 2
  • 👍 1
Post #2943 3.33K
CHALLENGE

class Calculator {
constructor(value) {
this.value = value;
}

add(num) {
this.value += num;
return this;
}

multiply(num) {
this.value *= num;
return this;
}
}

const calc = new Calculator(5);
const addMethod = calc.add;
const result = addMethod.call(calc, 3).multiply(2);
console.log(result.value);
  • 🔥 8
  • ❤ 6
  • 👍 5
Post #2942 3.15K
👀 Superdiff 4.0: Compares Arrays or Objects and Returns a Diff

Got two similar objects or arrays and want to see the underlying differences? Superdiff has been around a while, but recent updates boost performance, add support for streamed input and using a worker for more efficient diffing in a background thread. The project now has a handy documentation site too.

antoine
  • ❤ 9
  • 🔥 4
  • 👍 3
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 →