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
31K
Photos
1.2K
Videos
10
Links
899

Showing posts older than #2193 Β· Back to latest

Older Posts 20 shown
Post #2192 4.99K
CHALLENGE

function processConfig(config) {
const cache = config.cache ?? true;
const timeout = config.timeout ?? 1000;
const retries = config.retries ?? 3;

return {
useCache: cache,
timeoutMs: timeout,
maxRetries: retries
};
}

const result = processConfig({ timeout: 0, retries: false });
console.log(result);
  • πŸ‘ 3
Post #2190 5.57K
  • πŸ”₯ 6
  • πŸ‘ 4
  • ❀ 2
Post #2189 5.38K
CHALLENGE

type User = {
id: number;
name: string;
role?: 'admin' | 'user';
};

function processUser(user: Partial<User>): string {
const defaultUser: User = {
id: 0,
name: 'Guest',
role: 'user'
};

const mergedUser = { ...defaultUser, ...user };

if (mergedUser.role === 'admin') {
return `Admin: ${mergedUser.name}`;
}

return `User: ${mergedUser.name} (ID: ${mergedUser.id})`;
}

console.log(processUser({ name: 'John', role: 'admin' }));
  • πŸ‘ 7
  • ❀ 1
Post #2188 5.26K
  • πŸ‘ 8
  • πŸ€” 7
  • ❀ 3
  • πŸ”₯ 1
Post #2187 5.52K
CHALLENGE

const target = { a: 1, b: 2 };
const handler = {
get(obj, prop) {
return prop in obj ? obj[prop] * 2 : 'Not found';
}
};

const proxy = new Proxy(target, handler);

// Add a property to the original target
target.c = 3;

// Attempt to access properties through proxy and Reflect
console.log([
proxy.a,
proxy.z,
Reflect.get(target, 'b'),
Reflect.get(proxy, 'c')
]);
  • πŸ‘ 4
Post #2186 5.19K
😭
  • πŸ€” 32
  • πŸ‘ 6
  • ❀ 2
Post #2185 5.31K
  • πŸ‘ 6
  • ❀ 4
  • πŸ€” 3
Post #2184 5.51K
CHALLENGE

function Vehicle(type) {
this.type = type;
}

Vehicle.prototype.getType = function() {
return this.type;
};

function Car(make) {
this.make = make;
}

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

const myCar = new Car('Tesla');
myCar.type = 'electric';

console.log(myCar.getType(), myCar instanceof Vehicle, myCar.constructor.name);
  • ❀ 1
Post #2183 4.99K
πŸ‘ Introducing Motion for Vue

Motion is a popular and powerful animation library most commonly associated with React, but now there’s a new Vue flavor and it’s feature complete, too.

Matt Perry (Motion)
  • πŸ‘ 6
  • ❀ 5
Post #2182 5.65K
  • πŸ‘ 7
  • 🀩 5
Post #2181 5.47K
CHALLENGE

const user = {
profile: {
name: 'Alice',
social: null,
getDetails() {
return { verified: true };
}
}
};

const result = [
user?.profile?.name,
user?.profile?.social?.handle,
user.profile.getDetails?.()?.verified,
user?.nonExistent?.property
];

console.log(result);
  • πŸ‘ 7
Post #2180 5.35K
πŸ€” How to Build a Snake AI Game with Docker and TensorFlow.js

You’ve probably heard about people β€˜vibe coding’ games by letting LLMs do the coding work, but what if you want to build a game yourself that has neural network powered elements? TensorFlow.js offers one solution that you could just as easily adapt to non-gaming contexts.

Manvar and Raina (Docker)
  • πŸ‘ 10
  • ❀ 2
  • πŸ”₯ 2
Post #2179 5.32K
  • πŸ‘ 9
  • 🀣 8
  • 🀩 5
  • πŸ”₯ 4
  • ❀ 3
Post #2178 5.13K
CHALLENGE

function* counter() {
let count = 1;
while (true) {
const reset = yield count++;
if (reset) {
count = 1;
}
}
}

const gen = counter();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next(true).value);
console.log(gen.next().value);
  • πŸ‘ 8
  • πŸ”₯ 2
  • ❀ 1
  • πŸ€” 1
Post #2177 5.39K
  • ❀ 8
  • πŸ‘ 1
  • πŸ”₯ 1
Post #2176 5.41K
🀨 Rsdoctor 1.0: An Analyzer for Rspack and Webpack

A one-stop, intelligent build analyzer making it easier to identify bottlenecks and optimize performance. It’s part of the same family of tools as Rspack (a Rust-powered web bundler) but is fully webpack compatible. If you’ve ever asked why your build times are too long, this is for you.

ByteDance Inc.
  • πŸ‘ 5
  • πŸ”₯ 2
  • ❀ 1
Post #2175 4.94K
CHALLENGE

function* fibonacci() {
let [prev, curr] = [0, 1];
while (true) {
yield curr;
[prev, curr] = [curr, prev + curr];
}
}

function* take(iterable, limit) {
for (const item of iterable) {
if (limit <= 0) return;
yield item;
limit--;
}
}

const fibs = [...take(fibonacci(), 5)];
fibs.push(fibs[0] + fibs[1]);
console.log(fibs);
  • ❀ 3
  • πŸ‘ 3
  • πŸ€” 1
Post #2174 5.05K
  • πŸ€” 14
  • 🀣 11
  • πŸ‘ 10
  • πŸ”₯ 6
  • ❀ 4
Post #2173 5.23K
CHALLENGE

function createCounter() {
let count = 0;

return function() {
count++;
return count;
};
}

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

counter1();
counter1();
counter2();

const result = counter1() + counter2();
console.log(result);
  • πŸ‘ 6
  • 🀣 6
  • πŸ€” 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 β†’