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 #3368 · Back to latest

Older Posts 20 shown
Post #3366 2.64K
CHALLENGE

const user = {
profile: {
name: "Marcus",
address: {
city: "Berlin",
zip: "10115"
}
},
getSubscription: () => ({
plan: "pro",
features: ["analytics", "exports"]
})
};

const city = user?.profile?.address?.city;
const country = user?.profile?.address?.country?.toUpperCase();
const firstFeature = user?.getSubscription?.()?.features?.[0];
const adminRole = user?.roles?.[0]?.name ?? "guest";

console.log(city, country, firstFeature, adminRole);
  • 🔥 4
  • 👍 3
  • ❤ 2
  • 🤩 2
Post #3365 2.37K
  • ❤ 3
  • 👍 1
Post #3364 2.56K
CHALLENGE


function createUser(
name,
role = "viewer",
permissions = { read: true, write: false },
level = permissions.write ? 2 : 1
) {
return { name, role, permissions, level };
}

const user1 = createUser("Carlos");
const user2 = createUser("Diana", "editor", { read: true, write: true });
const user3 = createUser("Eve", "admin", undefined, 5);

console.log(user1.role, user1.level);
console.log(user2.role, user2.level);
console.log(user3.role, user3.level);
  • 🔥 5
  • 👍 2
  • 🤩 2
Post #3363 2.46K
  • 🤔 3
  • ❤ 1
Post #3362 2.56K
CHALLENGE

const flags = {
READ: 0b0001,
WRITE: 0b0010,
EXECUTE: 0b0100,
DELETE: 0b1000,
};

const userPermissions = flags.READ | flags.WRITE | flags.EXECUTE;
const adminPermissions = userPermissions | flags.DELETE;

const canDelete = (adminPermissions & flags.DELETE) !== 0;
const readOnly = userPermissions & ~flags.WRITE;

const toggled = userPermissions ^ flags.EXECUTE;
const shifted = (flags.DELETE << 2) | (flags.READ >> 0);

console.log(canDelete, readOnly, toggled, shifted);
  • ❤ 3
  • 👍 2
  • 🔥 1
Post #3361 2.54K
  • 🔥 2
  • 🤣 2
Post #3360 2.63K
CHALLENGE

const obj = {
name: "Quantum",
regular: function () {
return this.name;
},
arrow: () => {
return this?.name;
},
nested: function () {
const inner = () => this.name;
return inner();
},
};

console.log(obj.regular());
console.log(obj.arrow());
console.log(obj.nested());
  • ❤ 4
  • 👍 4
  • 🔥 4
Post #3359 2.64K
  • 🔥 2
  • ❤ 1
Post #3358 2.68K
CHALLENGE


const curry = (fn) => {
const arity = fn.length;
return function curried(...args) {
if (args.length >= arity) {
return fn(...args);
}
return (...moreArgs) => curried(...args, ...moreArgs);
};
};

const volume = (l, w, h) => l * w * h;
const curriedVolume = curry(volume);

const withLength5 = curriedVolume(5);
const withLength5Width3 = withLength5(3);

console.log(typeof withLength5);
console.log(typeof withLength5Width3);
console.log(withLength5Width3(2));
console.log(curriedVolume(5)(3)(2) === withLength5(3)(2));
  • ❤ 4
  • 🔥 3
  • 👍 1
Post #3357 2.55K
  • ❤ 4
  • 🔥 1
Post #3356 2.39K
CHALLENGE

console.log('start');

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

Promise.resolve()
.then(() => {
console.log('promise 1');
setTimeout(() => console.log('timeout 2'), 0);
})
.then(() => console.log('promise 2'));

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

queueMicrotask(() => console.log('microtask'));

console.log('end');
  • ❤ 5
  • 🔥 3
  • 👍 2
Post #3355 2.57K
🤖 Eve: A Next.js-Style Framework for Building Agents

A new framework from Vercel that provides Next.js-esque structure for building AI-powered agents using TypeScript and Markdown. It's quite Vercel-flavored by default, but I found you can run it entirely independently of Vercel with a few settings tweaks and your own keys. Project homepage.

Vercel
  • ❤ 4
  • 🔥 2
Post #3354 2.57K
  • ❤ 1
  • 🔥 1
Post #3353 2.71K
CHALLENGE

class Pipeline {
#value;
#steps = [];

constructor(value) {
this.#value = value;
}

map(fn) {
this.#steps.push({ type: 'map', fn });
return this;
}

filter(fn) {
this.#steps.push({ type: 'filter', fn });
return this;
}

execute() {
return this.#steps.reduce((acc, step) => {
if (step.type === 'map') return acc.map(step.fn);
if (step.type === 'filter') return acc.filter(step.fn);
return acc;
}, this.#value);
}
}

const result = new Pipeline([1, 2, 3, 4, 5, 6])
.filter(x => x % 2 === 0)
.map(x => x ** 2)
.filter(x => x > 10)
.map(x => x - 1)
.execute();

console.log(result);
  • 👍 5
  • ❤ 2
  • 🔥 1
Post #3352 2.58K
🤟 Node.js 26.4 Adds Package Maps

A minor release whose headline feature is the (experimental) implementation of package maps (which let Node resolve packages from a static JSON file rather than walking node_modules). Matteo Collina’s node:vfs subsystem also begins to make an appearance.

Antoine du Hamel
  • 👍 6
  • ❤ 3
  • 🔥 1
Post #3350 2.78K
😃 Wordgard: A New Rich Text Editor Library from ProseMirror's Creator

With Eloquent JavaScript and ProseMirror under his belt, not many people know more about JavaScript and making good editor controls than Marijn. Modular, supports collaborative editing, and thoughtfully built. Live demo and how to get started.

Marijn Haverbeke
  • ❤ 7
  • 🔥 3
Post #3349 2.76K
  • 👍 3
  • ❤ 1
  • 🤩 1
  • 🤣 1
Post #3348 2.85K
CHALLENGE

const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);
const pipe = (...fns) => x => fns.reduce((acc, fn) => fn(acc), x);

const double = x => x * 2;
const addTen = x => x + 10;
const square = x => x ** 2;
const negate = x => -x;

const transform1 = compose(negate, square, addTen, double);
const transform2 = pipe(negate, square, addTen, double);

console.log(transform1(3));
console.log(transform2(3));
  • 🔥 3
  • ❤ 2
  • 🤩 1
Post #3347 2.79K
😮 Vite+ Beta: A Web Dev Toolchain Behind One Command

Vite+ is the Vite team’s ‘unified toolchain’ that brings Vite, Vitest, Oxlint, and similar tools together under a single vp command, whether for running a dev server, tests, formatting, or bundling.

VoidZero

💡 Vite+ was originally intended to be a commercial project to fund work on Vite and related projects, but was open sourced under the MIT license earlier this year.
  • ❤ 5
  • 👍 4
  • 🔥 2
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 →