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 #2254 ยท Back to latest

Older Posts 20 shown
Post #2252 5.05K
  • ๐Ÿ‘ 6
  • ๐Ÿคฉ 5
  • โค 2
  • ๐Ÿ”ฅ 2
Post #2251 5K
CHALLENGE

function executePromises() {
console.log(1);

setTimeout(() => {
console.log(2);
}, 0);

Promise.resolve().then(() => {
console.log(3);
setTimeout(() => {
console.log(4);
}, 0);
}).then(() => {
console.log(5);
});

console.log(6);
}

executePromises();
  • โค 3
  • ๐Ÿ”ฅ 3
  • ๐Ÿ‘ 1
Post #2250 4.95K
๐Ÿ˜†
  • ๐Ÿคฃ 45
  • ๐Ÿ‘ 12
  • โค 2
  • ๐Ÿ”ฅ 1
  • ๐Ÿค” 1
Post #2249 5.09K
  • ๐Ÿ‘ 3
  • โค 2
  • ๐Ÿ”ฅ 2
Post #2248 5.03K
CHALLENGE

const user = {
name: 'Alice',
age: 30
};

const handler = {
get(target, prop) {
if (prop in target) {
return target[prop];
}
return `Property '${prop}' doesn't exist`;
},
set(target, prop, value) {
if (prop === 'age' && typeof value !== 'number') {
console.log('Age must be a number');
return false;
}
target[prop] = value;
return true;
}
};

const proxy = new Proxy(user, handler);
proxy.age = '32';
proxy.age = 32;
console.log(proxy.job);
  • ๐Ÿ‘ 7
  • โค 3
Post #2247 5.19K
๐Ÿ˜†
  • ๐Ÿคฃ 39
  • โค 4
  • ๐Ÿ”ฅ 4
  • ๐Ÿ‘ 1
Post #2246 5.2K
๐ŸคŸ Lexe: Package a Node App into a Single Executable

Node actually has a mechanism for creating single executable applications and there are numerous other tools to do it, but Lexe takes the approach of using Amazonโ€™s lightweight LLRT engine to make binaries of under 10MB in size. Note, however, "Lexe is not a drop-in replacement for Node.js. It only supports a subset of Node.js APIs."

Ray-D-Song
  • ๐Ÿ‘ 6
  • โค 3
  • ๐Ÿ”ฅ 1
Post #2245 4.76K
  • ๐Ÿ‘ 5
  • โค 2
  • ๐Ÿ”ฅ 1
Post #2244 4.95K
CHALLENGE

const privateData = new WeakMap();

function Person(name) {
privateData.set(this, { name, secretCount: 0 });

this.greet = function() {
const data = privateData.get(this);
data.secretCount++;
return `Hello, my name is ${data.name}`;
};

this.getSecretCount = function() {
return privateData.get(this).secretCount;
};
}

const alice = new Person('Alice');
alice.greet();
alice.greet();

const result = [
privateData.has(alice),
alice.name,
alice.getSecretCount()
];

console.log(result);
  • ๐Ÿ‘ 4
  • โค 1
Post #2243 4.91K
๐Ÿ™‚ Fastify + React โ€“ 7x Faster than Next.js?

Nodeโ€™s Fastify framework has a mature plugin for Vite integration (explained in detail here), including @fastify/react which just hit version 1.0 and makes it easy to create fast, featureful (though obviously less so than Next.js) React apps atop Fastify. How fast? Very, it seems.

Jonas Galvez
  • ๐Ÿค” 6
  • โค 3
  • ๐Ÿ‘ 2
  • ๐Ÿ”ฅ 1
Post #2242 4.84K
  • ๐Ÿ‘ 6
  • ๐Ÿ”ฅ 5
  • โค 2
  • ๐Ÿค” 1
Post #2241 5.15K
CHALLENGE

function* generateSequence() {
let i = 1;
while (i <= 3) {
yield i++;
}
}

function* extendSequence() {
yield* generateSequence();
yield* [4, 5];
yield 6;
}

const generator = extendSequence();
const result = [];

for (const value of generator) {
if (value % 2 === 0) {
result.push(value * 2);
} else {
result.push(value);
}
}

console.log(result);
  • โค 1
Post #2240 4.82K
๐Ÿ˜†
  • ๐Ÿคฃ 56
  • โค 5
  • ๐Ÿคฉ 4
  • ๐Ÿ‘ 2
Post #2239 5.15K
  • ๐Ÿค” 9
  • ๐Ÿ‘ 3
  • โค 2
Post #2238 5.15K
CHALLENGE

function createSymbolDemo() {
const obj = {};

const sym1 = Symbol('description');
const sym2 = Symbol('description');
const sym3 = Symbol.for('shared');
const sym4 = Symbol.for('shared');

obj[sym1] = 'Value 1';
obj[sym2] = 'Value 2';
obj[sym3] = 'Value 3';
obj[sym4] = 'Value 4';

console.log(Object.keys(obj).length, sym1 === sym2, sym3 === sym4, obj[sym3]);
}

createSymbolDemo();
  • ๐Ÿ‘ 6
  • โค 1
Post #2237 4.88K
๐Ÿ•ต๏ธ ๐—ช๐—ฒ ๐—ฐ๐—ฎ๐˜‚๐—ด๐—ต๐˜ ๐Ÿ‡ฐ๐Ÿ‡ต๐—Ÿ๐—ฎ๐˜‡๐—ฎ๐—ฟ๐˜‚๐˜€ ๐—›๐—ฎ๐—ฐ๐—ธ๐—ถ๐—ป๐—ด ๐—š๐—ฟ๐—ผ๐˜‚๐—ฝ ๐—ฑ๐—ฒ๐—ฏ๐˜‚๐—ด๐—ด๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ๐—ถ๐—ฟ ๐—ผ๐˜„๐—ป ๐—บ๐—ฎ๐—น๐˜„๐—ฎ๐—ฟ๐—ฒ... ๐—ถ๐—ป ๐—ฟ๐—ฒ๐—ฎ๐—น ๐˜๐—ถ๐—บ๐—ฒ.

A couple of weeks ago, something unexpected happened. While monitoring malicious uploads to the NPM ecosystem, we stumbled on a suspicious package: react-html2pdf.js (now suspended). At first glance, it looked innocuous. ๐—ก๐—ผ ๐—น๐—ถ๐—ณ๐—ฒ๐—ฐ๐˜†๐—ฐ๐—น๐—ฒ ๐—ต๐—ผ๐—ผ๐—ธ๐˜€. ๐—ก๐—ผ ๐—ผ๐—ฏ๐˜ƒ๐—ถ๐—ผ๐˜‚๐˜€ ๐—บ๐—ฎ๐—น๐˜„๐—ฎ๐—ฟ๐—ฒ. Just a basic function in the index.js file.

Mackenzie Jackson
  • ๐Ÿค” 6
  • ๐Ÿคฃ 6
  • โค 2
Post #2236 4.82K
  • ๐Ÿ‘ 6
  • โค 4
  • ๐Ÿ”ฅ 2
Post #2235 5.07K
CHALLENGE

const num1 = 9007199254740992n;
const num2 = 1n;

const result1 = num1 + num2;
const result2 = Number(num1) + Number(num2);
const result3 = num1 + BigInt(1);
const result4 = String(num1) + String(num2);

console.log(typeof result2 === typeof result1, result1 === result3, result4);
  • ๐Ÿ‘ 2
Post #2234 5.36K
๐Ÿ˜† Vibe coding Tax has become a real thing!

Cursor's new "pay as you go" strategy with better models drives 20-30% more code generation than you would typically do. For all of the "vibe coders" out there, this is becoming an exponential "coding tax" for products because more code equals more token consumption, which generates more code...

Tigran Bayburtsyan
  • ๐Ÿคฃ 17
  • ๐Ÿ‘ 4
  • โค 3
  • ๐Ÿค” 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 โ†’