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

Older Posts 20 shown
Post #3125 2.8K
👀 Fuse.js 7.3: Lightweight Fuzzy-Search

Want a search feature tolerant to ambiguous input without a dedicated backend? v7.3 adds per-term fuzzy matching and a static method for single string matching, while v7.4 beta adds worker-based distributed search for tackling huge datasets. A demo shows off the basics.

Kiro Risk
  • ❤ 9
  • 🔥 1
Post #3124 2.75K
  • ❤ 5
  • 🔥 1
Post #3123 2.67K
CHALLENGE


const name = "Carlos";
const age = 28;
const score = 95;

const player = {
name,
age,
score,
greet() {
return `${this.name} (${this.age}) scored ${this.score}`;
},
get rank() {
return this.score >= 90 ? "Gold" : "Silver";
}
};

const { name: playerName, rank, greet } = player;

console.log(`${playerName} | ${rank} | ${greet.call(player)}`);
  • 🤔 5
  • ❤ 3
  • 👍 1
Post #3122 2.7K
In CSS is DOOMed, Niels Leenheer shows off how he implemented a version of 1993's Doom using purely CSS rendering (with the game logic in JavaScript). Play it for yourself or check out the code.
  • 🔥 7
  • ❤ 5
Post #3121 3.03K
  • ❤ 3
  • 🤔 3
  • 👍 2
Post #3120 2.74K
CHALLENGE


function createUser(
name,
role = "viewer",
permissions = [role],
metadata = { createdBy: name, level: permissions.length }
) {
return { name, role, permissions, metadata };
}

const user1 = createUser("Carlos");
const user2 = createUser("Diana", "admin", ["read", "write", "delete"]);
const user3 = createUser("Eve", "editor", undefined, { createdBy: "system", level: 99 });

console.log(user1.role, user1.permissions, user1.metadata.level);
console.log(user2.metadata.createdBy, user2.permissions.length);
console.log(user3.permissions[0], user3.metadata.level);
  • ❤ 2
  • 👍 1
  • 🔥 1
Post #3119 2.9K
✌️ JSIR: A High-Level IR for JavaScript from Google

Google has open sourced a new tool (JSIR) and proposed an industry-standard IR (Intermediate Representation – if an AST tells you what the code looks like, an IR tells you what it does) for JavaScript. Already used at Google for analysis and code transformation, the underlying idea could form a foundation for a new generation of tooling.

Zhixun Tan (Google)
  • ❤ 4
  • 👍 4
  • 🔥 2
Post #3118 2.8K
  • ❤ 4
  • 🔥 1
Post #3117 2.97K
CHALLENGE

function Vehicle(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
this.speed = 0;
}

Vehicle.prototype.accelerate = function (amount) {
this.speed += amount;
return this;
};

Vehicle.prototype.describe = function () {
return `${this.year} ${this.make} ${this.model} going ${this.speed}km/h`;
};

function ElectricVehicle(make, model, year, range) {
Vehicle.call(this, make, model, year);
this.range = range;
}

ElectricVehicle.prototype = Object.create(Vehicle.prototype);
ElectricVehicle.prototype.constructor = ElectricVehicle;

ElectricVehicle.prototype.describe = function () {
return Vehicle.prototype.describe.call(this) + ` | Range: ${this.range}km`;
};

const car = new ElectricVehicle("Tesla", "Model 3", 2023, 500);
car.accelerate(60).accelerate(40);

console.log(car.describe());
console.log(car instanceof ElectricVehicle);
console.log(car instanceof Vehicle);
console.log(car.constructor === ElectricVehicle);
  • ❤ 2
Post #3115 3.3K
  • 🔥 8
  • ❤ 5
  • 👍 1
Post #3114 3.2K
CHALLENGE


const str = " Hello, World! ";

const result = str
.trim()
.split(", ")
.map((word, i) => {
if (i % 2 === 0) return word.toUpperCase();
return word.toLowerCase().replace("!", "@");
})
.reverse()
.join(" | ");

console.log(result);
  • ❤ 3
Post #3113 3.32K
  • ❤ 5
  • 👍 3
Post #3112 2.91K
CHALLENGE

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

const p1 = delay(300, "alpha");
const p2 = Promise.reject("network error");
const p3 = delay(100, "gamma");
const p4 = Promise.reject("timeout");

Promise.allSettled([p1, p2, p3, p4]).then(results => {
const summary = results.map(r =>
r.status === "fulfilled"
? `ok:${r.value}`
: `fail:${r.reason}`
);
console.log(summary.join(" | "));
});
  • 👍 3
  • 🔥 2
  • ❤ 1
Post #3111 3.04K
🤔 axios Package Compromised; Malicious Versions Added a Trojan Dependency

Axios is an HTTP library that gets 100M+ downloads a week, largely due to its legacy popularity. An attacker took advantage of that to roll out a version with a malicious dependency including a remote access trojan (though Axios' codebase itself was fine). This is big, as even if you don’t use Axios, your dependencies might. Here's how to see if you're affected.

Ashish Kurmi
  • ❤ 4
  • 🔥 4
  • 🤔 3
  • 🤩 1
Post #3109 2.83K
CHALLENGE

function* range(start, end) {
while (start < end) {
yield start++;
}
}

function* evens(iter) {
for (const val of iter) {
if (val % 2 === 0) yield val;
}
}

function* take(n, iter) {
let count = 0;
for (const val of iter) {
if (count++ >= n) return;
yield val;
}
}

function* pipeline() {
yield* take(3, evens(range(1, 20)));
yield* take(2, range(10, 15));
}

const result = [...pipeline()];
console.log(result);
  • 🔥 2
  • 👍 1
Post #3108 2.64K
  • ❤ 4
  • 🔥 2
  • 👍 1
Post #3107 2.76K
CHALLENGE

const handler = {
get(target, prop, receiver) {
if (prop in target) {
return Reflect.get(target, prop, receiver) * 2;
}
return `Missing: ${prop}`;
},
set(target, prop, value) {
if (typeof value !== "number") {
throw new TypeError("Only numbers allowed");
}
return Reflect.set(target, prop, Math.abs(value));
},
};

const store = new Proxy({ gold: 10, silver: 5 }, handler);

store.bronze = -42;

console.log(store.gold);
console.log(store.bronze);
console.log(store.platinum);
  • ❤ 4
  • 🔥 3
Post #3106 2.47K
  • ❤ 3
  • 🔥 2
  • 👍 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 →