javascript | Unsorted

Telegram-канал javascript - JavaScript

31615

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

Subscribe to a channel

JavaScript

CHALLENGE

class Config {
constructor(options = {}) {
this.retries = options.retries ?? 3;
this.timeout = options.timeout ?? 1000;
}
}
const cfg1 = new Config({ retries: 0, timeout: null });
const cfg2 = new Config({ retries: undefined, timeout: false });
cfg1.retries ??= 99;
cfg2.timeout ??= 99;
console.log(cfg1.retries, cfg1.timeout, cfg2.retries, cfg2.timeout);

Читать полностью…

JavaScript

CHALLENGE

const a = [] + {};
const b = {} + [];
const c = 1 + '1' - 1;
const d = '5' + 3 - 2;
const e = true + true;
console.log(a, b, c, d, e);

Читать полностью…

JavaScript

CHALLENGE

function tag(strings, ...values) {
return strings.raw.join('|') + '=' + values.reduce((sum, v) => sum + v, 0);
}
const x = 5;
const y = 10;
console.log(tag`Sum\n${x}and${y}end`);

Читать полностью…

JavaScript

CHALLENGE

function tag(strings, ...values) {
// strings.raw preserves literal escape sequences
const rawParts = strings.raw;
let result = rawParts.join('|');
result += '::' + values.join(',');
return result;
}

const x = 5;
const output = tag`Line1\nLine2${x}End`;
console.log(output);

Читать полностью…

JavaScript

CHALLENGE

function* inner() {
yield 1;
yield 2;
return 10;
}

function* outer() {
const result = yield* inner();
yield result;
yield 3;
}

const gen = outer();
const a = gen.next().value;
const b = gen.next().value;
const c = gen.next().value;
const d = gen.next().value;
console.log(a, b, c, d);

Читать полностью…

JavaScript

CHALLENGE

class Base {
static count = 0;
static #secret;
static {
Base.#secret = 10;
Base.count += 1;
}
static getSecret() {
return Base.#secret;
}
}

class Derived extends Base {
static {
Base.count += 100;
}
}

console.log(Base.count, Derived.count, Base.getSecret());

Читать полностью…

JavaScript

CHALLENGE

const source = {
_val: 1,
get val() { return this._val; }
};
const copy1 = Object.assign({}, source);
source._val = 100;
const copy2 = { ...source };
copy1._val = 999;
console.log(copy1.val, copy2.val, source.val, copy1._val);

Читать полностью…

JavaScript

CHALLENGE

const primArr = [1, 2, 3];
const copyArr = [...primArr];
copyArr[0] = 99;

const objArr = [{ x: 1 }, { x: 2 }];
const copyObjArr = [...objArr];
copyObjArr[0].x = 99;

console.log(primArr[0], copyArr[0], objArr[0].x, copyObjArr[0].x);

Читать полностью…

JavaScript

CHALLENGE

class Timer {
constructor() { this.seconds = 0; }
start() {
this.tick = () => { this.seconds++; return this.seconds; };
return this.tick;
}
}

const t = new Timer();
const tick = t.start();
const obj = { seconds: 100, tick };
console.log(tick(), obj.tick(), t.seconds);

Читать полностью…

JavaScript

😮 How a Fake Interview's Coding Challenge Steals Credentials

A dissection of a North Korean campaign that hides malware inside SVG images in a fake job interview's JavaScript 'coding challenge'. The targeting of job-seeking devs is on the increase, as Roman Imankulov recently discovered first-hand.

Daniel Stepanic (Elastic)

Читать полностью…

JavaScript

🤩 Flint: Chart Specs that Compile to Vega-Lite, ECharts, or Chart.js

A Microsoft project that compiles a simple, declarative JSON-based spec of a data visualization into a form that Vega-Lite, ECharts or Chart.js can render. It's pitched at agentic use, but is a simple intermediate format humans could benefit from too.

Microsoft Research

Читать полностью…

JavaScript

CHALLENGE

function* pipeline(...fns) {
let value = yield;
for (const fn of fns) {
value = yield fn(value);
}
return value;
}

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

const gen = pipeline(double, addTen, square);

gen.next(); // prime the generator
const r1 = gen.next(3);
const r2 = gen.next(r1.value);
const r3 = gen.next(r2.value);

console.log(r1.value, r2.value, r3.value);

Читать полностью…

JavaScript

CHALLENGE


const p1 = new Promise((resolve) => {
console.log("A");
resolve("B");
});

const p2 = p1.then((val) => {
console.log(val);
return "C";
});

p2.then((val) => {
console.log(val);
});

console.log("D");

Читать полностью…

JavaScript

☔️ AWS billing issues

Читать полностью…

JavaScript

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);

Читать полностью…

JavaScript

CHALLENGE

let arr = [];
for (let i = 0; i < 3; i++) {
if (i === 1) {
let i = 10;
arr.push(i);
continue;
}
arr.push(i);
}
console.log(arr.join('-'));

Читать полностью…

JavaScript

CHALLENGE

const order = [];
const log = (s) => order.push(s);

log('start');

Promise.resolve().then(() => {
log('p1');
return Promise.resolve();
}).then(() => log('p1-2'));

async function foo() {
log('foo-start');
await null;
log('foo-end');
}

foo();

Promise.resolve().then(() => log('p2'));

log('end');

setTimeout(() => console.log(order.join(' ')), 0);

Читать полностью…

JavaScript

CHALLENGE

const config = { retries: 0, timeout: null, name: '' };
const a = config.retries || 5;
const b = config.timeout ?? 10;
const c = config.name || 'default';
const d = config.missing?.value ?? 'fallback';
let calls = 0;
const sideEffect = () => { calls++; return true; };
const e = config.retries && sideEffect();
console.log(a, b, c, d, e, calls);

Читать полностью…

JavaScript

🥶 scriptc: Vercel's New TypeScript-to-Native Compiler

A new entry into the growing field of JS/TS native ahead-of-time compilers that makes the promise that "what compiles behaves byte-for-byte like Node." Static by default, but you can opt in to a --dynamic mode which embeds a JavaScript engine for runtime dynamism. GitHub repo.

Vercel Labs

Читать полностью…

JavaScript

⛽️ The Secure Way to Release an npm Package in 2026

A practical guide to publishing npm packages more safely in 2026, written by someone who's released several popular packages (like postcss and nanoid). As well as showing how to use things like staged publishing and trusted publishing, he explains why and the security benefits of doing so.

Andrey Sitnik

Читать полностью…

JavaScript

CHALLENGE

function Animal(name) {
this.name = name;
}
Animal.prototype.speak = function () {
return `${this.name} makes a sound`;
};

function Dog(name) {
Animal.call(this, name);
}
Dog.prototype = Object.create(Animal.prototype);
Dog.prototype.constructor = Dog;
Dog.prototype.speak = function () {
return `${Animal.prototype.speak.call(this)} (bark)`;
};

const d = new Dog('Rex');
console.log(
d.speak(),
d instanceof Animal,
d.constructor === Dog,
Object.getPrototypeOf(d) === Dog.prototype
);

export {};

Читать полностью…

JavaScript

CHALLENGE

const arr = [1, [2, 3], [4, [5, 6]], 7];
const a = arr.flat();
const b = arr.flat(2);
const c = arr.flatMap(x => Array.isArray(x) ? x : [x, x]);
const d = [1, 2, 3].flatMap(x => [[x]]);
console.log(JSON.stringify([a, b, c, d]));

Читать полностью…

JavaScript

🙂 Follow a Single HTTP Request Through Its ~200ms Life

From the creator of NodeBook, a thorough guide to Node's internals, comes a scroll-driven visualization following every step a single HTTP POST request takes from the user's click to Node's event loop and on to a database behind it.

Ishtmeet Singh

Читать полностью…

JavaScript

😲 LiteParse 2: Fast, Light PDF Document Parsing

A PDF parser built in Rust with bindings for Node (plus WASM, Rust, and Python) — it worked great in my testing. It includes OCR, handles layouts/is spatially aware, and is fast (a complex 140-page PDF took ~10 seconds). Here's how to get started from Node.

LlamaIndex

Читать полностью…

JavaScript

Famously, the only thing Java gave JavaScript was the first four letters of its name. That goes unmentioned in 😉 this new documentary about Java (74 minutes), but I enjoyed learning Java's story anyway. It's from the same folks as the fantastic Vite, Angular, and Node.js documentaries.

Читать полностью…

JavaScript

😃 Framework Benchmarks: Compare Frontend Frameworks

An experienced developer built and benchmarked the same app across numerous frameworks (e.g. Angular, Solid, React, Alpine.js…). Here are the results, covering bundle size, build time, UX metrics, and more.

Alicia Sykes

Читать полностью…

JavaScript

CHALLENGE

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

const product = "widget";
const qty = 4;
const price = 12.5;

const output = highlight`Order: ${product} x${qty} @ $${price}`;
console.log(output);

Читать полностью…

JavaScript

CHALLENGE

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

const name = "carlos";
const score = 42;
const bonus = null;

const output = tag`Player: ${name}, Score: ${score}, Bonus: ${bonus}`;
console.log(output);

Читать полностью…

JavaScript

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);

Читать полностью…

JavaScript

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);

Читать полностью…
Subscribe to a channel