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

Older Posts 20 shown
Post #3105 2.65K
CHALLENGE

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

const language = "javascript";
const year = 2015;
const feature = "templates";

const output = highlight`Language: ${language}, introduced in ${year}, feature: ${feature}!`;
console.log(output);
  • ❤ 7
  • 👍 2
  • 🔥 2
Post #3104 2.6K
  • ❤ 5
  • 👍 2
  • 🔥 2
  • 🤔 1
  • 🤣 1
Post #3103 2.6K
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(4));
console.log(curriedVolume(2)(6)(7));
  • ❤ 5
  • 👍 2
  • 🔥 2
Post #3102 2.73K
  • ❤ 5
  • 👍 3
  • 🔥 2
  • 🤔 1
Post #3101 2.8K
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());
  • ❤ 3
  • 👍 2
  • 🔥 1
Post #3100 2.81K
  • ❤ 4
  • 🔥 2
  • 👍 1
Post #3099 2.82K
CHALLENGE


"use strict";

function createCounter() {
let count = 0;

return {
increment() { count++; },
getCount() { return count; },
reset: function() { count = 0; }
};
}

const counter = createCounter();
counter.increment();
counter.increment();
counter.increment();

const { getCount, reset } = counter;

try {
reset();
console.log("After reset:", counter.getCount());
} catch (e) {
console.log("Error:", e.message);
}

console.log("Direct call:", counter.getCount());
  • ❤ 6
  • 👍 1
  • 🔥 1
Post #3098 2.59K
  • ❤ 3
  • 🔥 2
Post #3097 2.85K
CHALLENGE


const operations = {
add: (a, b) => a + b,
subtract: (a, b) => a - b,
multiply: (a, b) => a * b,
divide: (a, b) => b !== 0 ? a / b : null,
};

const pipeline = (...fns) => (value) => fns.reduce((acc, fn) => fn(acc), value);

const double = (x) => operations.multiply(x, 2);
const addTen = (x) => operations.add(x, 10);
const halve = (x) => operations.divide(x, 2);
const subtractThree = (x) => operations.subtract(x, 3);

const transform = pipeline(double, addTen, halve, subtractThree);

console.log(transform(5));
  • ❤ 8
  • 🔥 1
Post #3096 2.57K
👀 The Three Pillars of JavaScript Bloat

Three reasons your node_modules is huge: needless ES3-era compat packages, micro-libraries with a single consumer, and ponyfills for APIs that shipped years ago! James, known for the e18e ecosystem performance project, offers some ways to calm the chaos.

James Garbutt
  • ❤ 5
  • 🔥 4
Post #3095 2.74K
  • 👍 5
  • ❤ 2
Post #3094 2.75K
CHALLENGE


const obj = {
name: "Orion",
greet() {
const inner = () => {
console.log(this.name);
};
inner();
},
greetRegular: function () {
const inner = function () {
console.log(this?.name ?? "undefined");
};
inner();
},
};

obj.greet();
obj.greetRegular();
  • ❤ 2
  • 👍 2
  • 🔥 2
Post #3093 2.86K
🥶 Announcing TypeScript 6.0

Over six months in the making, TypeScript 6.0 is designed to bridge the gap between its self-hosted compiler and the (almost ready) Go-powered native compiler of TypeScript 7.0 .

There are new features (Temporal improvements, RegExp.escape, and more), but most important are the changes to help you prepare for 7.0:

Numerous default changes: strict is now true, module is esnext, rootDir defaults to ., and more.
• A change that will affect many apps is types defaulting to [] rather than pulling in everything from node_modules/@types.
• Numerous deprecations: the es5 target, emitting AMD, UMD, and SystemJS modules, --baseUrl, and others.
• --stableTypeOrdering makes 6.0's type ordering behavior match 7.0's to help diagnose inference differences as you update.

Daniel Rosenwasser (Microsoft)
  • ❤ 12
  • 👍 3
  • 🔥 2
Post #3092 2.8K
  • ❤ 3
  • 🔥 3
  • 👍 2
Post #3091 3.04K
CHALLENGE

const compose = (...fns) => fns.reduce((f, g) => (...args) => f(g(...args)));

const pipe = (...fns) => fns.reduce((f, g) => (...args) => g(f(...args)));

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

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

const val = 3;

console.log(transform1(val), transform2(val));
  • 🔥 6
  • 👍 4
  • ❤ 1
Post #3090 2.89K
  • ❤ 5
  • 👍 1
Post #3089 3.01K
CHALLENGE


const a = 10n ** 3n;
const b = BigInt(Number.MAX_SAFE_INTEGER) + 1n;
const c = b + 1n;

console.log(typeof a);
console.log(a === 1000n);
console.log(b === c);
console.log(5n / 2n);
  • ❤ 3
  • 🔥 3
  • 👍 1
Post #3087 3.22K
  • 🔥 3
  • 👍 1
Post #3086 3.03K
CHALLENGE


const temperature = {
celsius: 22,
[Symbol.toPrimitive](hint) {
if (hint === 'number') {
return this.celsius;
}
if (hint === 'string') {
return `${this.celsius}°C`;
}
return this.celsius + 273.15;
}
};

console.log(`Temp: ${temperature}`);
console.log(temperature + 0);
console.log(temperature * 2);
console.log(+temperature);
  • ❤ 5
  • 🔥 5
  • 👍 2
Post #3085 2.85K
🤟 Evolving the Node.js Release Schedule: A Work in Progress

The Node.js team has long been discussing shifting Node to a new schedule of one major release per year (instead of two), removing the odd/even distinction, and making every release LTS (with a prior 11 months of alpha/current status). This is a preview post not intended for final publication till April, so things are subject to change (backup version).

The Node.js Team
  • ❤ 5
  • 👍 2
  • 🔥 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 →