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

Older Posts 20 shown
Post #3245 2.69K
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 canExecute = (userPermissions & flags.EXECUTE) !== 0;
const readOnly = userPermissions ^ flags.WRITE;

console.log(canDelete, canExecute, readOnly, adminPermissions >> 1);
  • ❤ 2
  • 👍 2
  • 🔥 1
Post #3243 2.65K
  • ❤ 4
  • 👍 1
Post #3242 2.46K
CHALLENGE


const config = {
db: { host: "localhost", port: 5432 },
cache: { ttl: 300 },
};

Object.freeze(config);

config.debug = true;
config.db.port = 9999;
config.cache = { ttl: 600 };

const sealed = Object.seal({ version: "1.0", meta: { build: 42 } });

sealed.version = "2.0";
sealed.author = "devteam";
sealed.meta.build = 99;

console.log(
config.debug,
config.db.port,
config.cache.ttl,
sealed.version,
sealed.author,
sealed.meta.build
);
  • ❤ 5
  • 👍 1
Post #3241 2.4K
🤟 An Official Codemod to Migrate from Axios to fetch

A codemod (used via npx codemod) that transforms code using Axios to leverage the WHATWG Fetch API, which is now natively available in Node.js. For some reason they don’t link to it in the post, but it’s here if you want to try it out (and here’s the underlying code).

Augustin Mauroy
  • ❤ 5
  • 👍 4
  • 🤩 1
  • 🤣 1
Post #3240 2.45K
  • ❤ 4
  • 🔥 1
Post #3239 2.58K
CHALLENGE

const prefix = "get";
const suffix = "Name";

const registry = {
[`${prefix}Full${suffix}`]: function () {
return `${this.first} ${this.last}`;
},
[`${prefix}Short${suffix}`]: function () {
return this.first[0] + ". " + this.last;
},
};

const person = {
first: "Leonardo",
last: "Fibonacci",
...registry,
};

const key = ["Full", "Short"][1];
console.log(person[`${prefix}${key}${suffix}`]());
  • ❤ 3
  • 👍 1
  • 🔥 1
Post #3238 2.79K
🤟 A Fresh Chapter and New Look for Express

For a while, Node’s long-standing web framework, Express.js, was looking a bit stale and projects like Fastify were beginning to carry the torch, but a major reboot that began in 2024 brought Express back to the fore. Now Express’s brand, website, and docs have time-travelled to 2026 too.

Sebastian Beltran
  • ❤ 7
  • 👍 3
  • 🤩 3
Post #3236 2.4K
CHALLENGE


const tag = (strings, ...values) => {
return strings.reduce((result, str, i) => {
const value = values[i - 1];
const transformed =
typeof value === "number" ? `[${value ** 2}]` : `{${value}}`;
return result + transformed + str;
});
};

const name = "Sofia";
const score = 4;
const level = "gold";

const output = tag`Player: ${name}, Score: ${score}, Rank: ${level}`;
console.log(output);
  • 🔥 3
  • ❤ 2
  • 👍 2
Post #3235 2.61K
✌️ Andrea Giammarchi proposes JSONRegistry (above), an alternative to JSON that lets you define a registry for serializing and reviving custom/branded types.
  • ❤ 6
  • 👍 1
  • 🔥 1
Post #3234 2.6K
  • ❤ 2
  • 🔥 1
Post #3233 2.43K
CHALLENGE

const delay = (ms, val) => new Promise(res => setTimeout(res, ms, val));

async function* asyncGen() {
yield await delay(10, "alpha");
yield await delay(10, "beta");
yield await delay(10, "gamma");
}

async function run() {
const results = [];

const gen = asyncGen();
const [first, , third] = await Promise.all([
gen.next(),
gen.next(),
gen.next()
]);

results.push(first.value, third.value);

const p1 = Promise.resolve("x").then(v => v + "1");
const p2 = Promise.reject("err").catch(e => e + "2");

results.push(...(await Promise.all([p1, p2])));
console.log(results);
}

run();
  • ❤ 8
  • 👍 3
Post #3231 2.38K
  • ❤ 4
  • 🔥 2
Post #3230 2.41K
CHALLENGE


const str = "JavaScript is Awesome!";

const result = str
.split(" ")
.map((word, i) =>
i % 2 === 0
? word.toUpperCase()
: word.toLowerCase()
)
.join("-");

const reversed = result
.split("")
.reduce((acc, char) => char + acc, "");

console.log(reversed);
  • 🔥 2
  • ❤ 1
Post #3229 2.35K
🤖 Mark Erikson's Agent Setup, Workflow, and Tools

Mark, well known for maintaining Redux and creating Redux Toolkit, goes deep into his daily development workflow, including his use of OpenCode (an open source JavaScript-powered coding agent), how he manages his knowledge base, tasks, and more.

Mark Erikson
  • ❤ 6
  • 🔥 4
  • 👍 3
Post #3228 2.21K
  • ❤ 3
  • 👍 2
Post #3227 2.34K
CHALLENGE


const createModule = (() => {
const privateCache = new WeakMap();

return function(name) {
const state = { name, version: 1, active: true };
privateCache.set(state, { accessCount: 0 });

return {
getInfo() {
const meta = privateCache.get(state);
meta.accessCount++;
return `${state.name}@v${state.version}`;
},
getAccessCount() {
return privateCache.get(state).accessCount;
},
upgrade() {
state.version++;
return this;
}
};
};
})();

const mod = createModule("auth");
mod.upgrade().upgrade();
console.log(mod.getInfo());
console.log(mod.getAccessCount());
  • ❤ 2
  • 👍 1
Post #3226 2.2K
⛽️ RFC: It’s Time for npm to Make Install Scripts Opt-In

npm is the only major package manager that runs dependency install scripts (e.g. postinstall) by default, and they’ve become too much of a security weakness, says Jamie, who works for GitHub (maintainers of npm). This RFC features further discussion of the idea and the tradeoffs involved.

Jamie Magee
  • ❤ 4
  • 🔥 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 →