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

Older Posts 20 shown
Post #2696 3.82K
CHALLENGE

const multiply = (a) => (b) => (c) => a * b * c;

const step1 = multiply(2);
const step2 = step1(3);
const result1 = step2(4);

const partialMult = multiply(5)(6);
const result2 = partialMult(7);

const directResult = multiply(1)(8)(9);

console.log(result1);
console.log(result2);
console.log(directResult);
console.log(typeof step1);
console.log(typeof partialMult);
  • ❤ 1
Post #2695 3.75K
💻 How Deno Protects Against npm Exploits

The maintainers of the Deno runtime reflect on the recent npm ecosystem security issues and show off how Deno’s non-permissive explicit ‘secure by default’ model can help.

Andy Jiang
  • ❤ 5
  • 🔥 3
  • 👍 2
  • 🤩 2
Post #2694 3.79K
  • ❤ 6
  • 👍 1
  • 🔥 1
Post #2693 3.8K
CHALLENGE

const arr = [1, 2, 3, 4, 5];
const obj = { a: 1, b: 2, c: 3 };

const result1 = Object.keys(obj).length;
const result2 = arr.length;

delete obj.b;
obj.d = 4;

const result3 = Object.keys(obj).length;
const result4 = arr.push(6);

arr.length = 3;

const result5 = arr.length;
const result6 = Object.keys(obj).join('');

console.log(result1, result2, result3, result4, result5, result6);
  • 🤔 2
  • ❤ 1
Post #2692 3.71K
  • ❤ 11
  • 🤔 5
Post #2691 3.75K
CHALLENGE

function createCounter() {
let count = 0;
return function(increment = 1) {
count += increment;
return count;
};
}

const counter1 = createCounter();
const counter2 = createCounter();

console.log(counter1());
console.log(counter1(5));
console.log(counter2(3));
console.log(counter1());
console.log(counter2());
  • ❤ 1
Post #2690 3.88K
  • ❤ 2
  • 🤔 1
Post #2689 3.87K
CHALLENGE

const Flyable = {
fly() { return 'flying'; }
};

const Swimmable = {
swim() { return 'swimming'; }
};

function mixin(Base, ...mixins) {
mixins.forEach(mixin => Object.assign(Base.prototype, mixin));
return Base;
}

class Bird {}
class Fish {}

const FlyingFish = mixin(class extends Fish {}, Flyable, Swimmable);
const instance = new FlyingFish();
console.log(instance.swim());
console.log(instance.fly());
console.log(instance instanceof Fish);
Post #2688 3.61K
  • ❤ 9
  • 👍 3
  • 🔥 1
Post #2687 3.85K
CHALLENGE

class DataProcessor {
constructor(value) {
this.value = value;
}

transform(fn) {
return new DataProcessor(fn(this.value));
}

getValue() {
return this.value;
}
}

const multiply = x => x * 2;
const add = x => x + 10;
const square = x => x * x;

const result = new DataProcessor(5)
.transform(multiply)
.transform(add)
.transform(square)
.getValue();

console.log(result);
  • ❤ 3
Post #2686 3.62K
✌️ The State of JavaScript 2025 Survey

Each year, Devographics runs an epic survey of as many JavaScript community members as it can and turns the results into an interesting report on the state of the ecosystem – here’s the results from 2024. If you have the time, fill it in, especially as they format it in a way where you can actually learn about stuff as you go.

Devographics
  • ❤ 4
  • 🤔 2
  • 🔥 1
Post #2685 3.71K
  • 👍 10
  • 🤔 1
Post #2684 3.86K
CHALLENGE

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

class Dog extends Animal {
speak() {
return super.speak() + ' and barks';
}
}

const pet = new Dog('Rex');
console.log(pet.speak());
console.log(pet instanceof Animal);
console.log(pet.constructor.name);
  • ❤ 5
  • 👍 1
Post #2683 3.71K
  • 🔥 3
  • ❤ 2
  • 👍 1
Post #2682 3.84K
CHALLENGE

class EventEmitter {
constructor() { this.events = {}; }
on(event, fn) { (this.events[event] ||= []).push(fn); }
emit(event, data) { this.events[event]?.forEach(fn => fn(data)); }
}

class Logger {
log(msg) { console.log(`LOG: ${msg}`); }
}

class Counter {
constructor() { this.count = 0; }
increment() { this.count++; console.log(this.count); }
}

function withLogging(target) {
const logger = new Logger();
return new Proxy(target, {
get(obj, prop) {
if (typeof obj[prop] === 'function') {
return function(...args) {
logger.log(`calling ${prop}`);
return obj[prop].apply(obj, args);
};
}
return obj[prop];
}
});
}

const emitter = withLogging(new EventEmitter());
const counter = new Counter();
emitter.on('tick', () => counter.increment());
emitter.emit('tick');
emitter.emit('tick');
  • 🤔 6
Post #2680 4K
  • ❤ 4
  • 👍 3
Post #2679 3.88K
CHALLENGE

function processData() {
try {
console.log('processing');
return 'success';
} catch (error) {
console.log('error caught');
return 'failed';
} finally {
console.log('cleanup');
}
}

const result = processData();
console.log('result:', result);
  • 🔥 2
Post #2678 3.9K
🤟 A Year of Improving Node.js Compatibility in Cloudflare Workers

“We’ve been busy,” says Cloudflare which recently announced it’s bringing Node.js HTTP server support to its Workers function platform. This post goes deep into the technicalities, covering what areas of the standard library is supported, how the file system works (Workers doesn’t have a typical file system), how input/output streams work, and more. And you can use all of this now.

James M Snell (Cloudflare)
  • ❤ 9
  • 🔥 3
  • 👍 1
Post #2677 3.79K
  • ❤ 8
  • 👍 4
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 →