JavaScript
31.9K subscribers
1.01K photos
9 videos
33 files
693 links
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
Download Telegram
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
๐Ÿ•ต๏ธ ๐—ช๐—ฒ ๐—ฐ๐—ฎ๐˜‚๐—ด๐—ต๐˜ ๐Ÿ‡ฐ๐Ÿ‡ต๐—Ÿ๐—ฎ๐˜‡๐—ฎ๐—ฟ๐˜‚๐˜€ ๐—›๐—ฎ๐—ฐ๐—ธ๐—ถ๐—ป๐—ด ๐—š๐—ฟ๐—ผ๐˜‚๐—ฝ ๐—ฑ๐—ฒ๐—ฏ๐˜‚๐—ด๐—ด๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ๐—ถ๐—ฟ ๐—ผ๐˜„๐—ป ๐—บ๐—ฎ๐—น๐˜„๐—ฎ๐—ฟ๐—ฒ... ๐—ถ๐—ป ๐—ฟ๐—ฒ๐—ฎ๐—น ๐˜๐—ถ๐—บ๐—ฒ.

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
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
๐Ÿค”9๐Ÿ‘3โค2
๐Ÿ˜†
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿคฃ55โค5๐Ÿคฉ4๐Ÿ‘2
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
๐Ÿ‘6๐Ÿ”ฅ5โค2๐Ÿค”1
๐Ÿ™‚ 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
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿค”6โค3๐Ÿ‘2๐Ÿ”ฅ1
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
1๐Ÿ‘5โค2๐Ÿ”ฅ1
๐ŸคŸ 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
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘6โค3๐Ÿ”ฅ1
Please open Telegram to view this post
VIEW IN TELEGRAM
2๐Ÿคฃ37โค4๐Ÿ”ฅ4๐Ÿ‘1
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
๐Ÿ˜†
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿคฃ45๐Ÿ‘12โค2๐Ÿ”ฅ1๐Ÿค”1
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โค2๐Ÿ‘1
๐Ÿ‘6๐Ÿคฉ5โค2๐Ÿ”ฅ1
โœŒ๏ธ The ECMAScript Records and Tuples Proposal Has Been Withdrawn

Several years in the making, the record and tuples proposal offered two new deeply immutable data structures to JavaScript, but at this weekโ€™s TC39 meeting, the consensus was to drop it.
Please open Telegram to view this post
VIEW IN TELEGRAM
๐Ÿ‘7๐Ÿค”4๐Ÿคฃ3โค2๐Ÿ”ฅ1
CHALLENGE

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

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

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

Promise.resolve().then(() => console.log(6));

console.log(7);
}

main();
โค5๐Ÿ‘2