JavaScript
31.7K subscribers
991 photos
9 videos
33 files
679 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

function createCounter() {
let count = 0;

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

function decrement() {
count -= 1;
return count;
}

return { increment, decrement, value: () => count };
}

const counter = createCounter();
counter.increment();
counter.increment();
counter.decrement();

console.log(counter.value() + counter.increment());
❀4
❀3πŸ‘3🀣2πŸ€”1
🟠Vercel Acquires NuxtLabs

Vercel has acquired the company that caretakes the Nuxt project and employs some of its core team – a move Vue creator Evan You is quite optimistic about. Vercel now manages, or at least supports, several key projects like Next.js, Turborepo, Svelte, and shadcn/ui. Nuxt itself remains open source and has a promising future. Vercel’s Guillermo Rauch shares a little more about the move here.

NuxtLabs / Vercel
Please open Telegram to view this post
VIEW IN TELEGRAM
❀8πŸ‘1πŸ”₯1
CHALLENGE

const memoryLeak = () => {
const cache = new Map();
const weakCache = new WeakMap();

const objKey = { id: 123 };
const data = { name: 'User data', value: 42 };

cache.set(objKey, data);
weakCache.set(objKey, data);

// Simulate removing reference to key
const result = { map: cache.has(objKey), weakMap: weakCache.has(objKey) };
// objKey = null; // This would be an error, as const can't be reassigned

return result;
};

console.log(memoryLeak());
❀6πŸ€”2
CHALLENGE

function createCounter() {
let count = 0;

return {
increment() {
return ++count;
},
reset() {
const oldCount = count;
count = 0;
return oldCount;
}
};
}

const counterA = createCounter();
const counterB = createCounter();

counterA.increment();
counterA.increment();
counterB.increment();
const result = counterA.reset() + counterB.reset();
console.log(result);
❀3
What is the output?
Anonymous Quiz
21%
undefined
23%
NaN
47%
3
8%
2
❀5
✌️ What’s the Difference Between Ordinary Functions and Arrow Functions?

This sounds like basic stuff, but James always does a good job of digging in and explaining things in a way that gives you a more nuanced way to think about a concept, even if it’s just β€œWhich function declaration syntax should I use?”

James Sinclair
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘7❀2πŸ”₯1
CHALLENGE

const users = [
{ id: 1, name: 'Sarah' },
{ id: 2, name: 'Miguel' },
{ id: 3, name: 'Jordan' }
];

const activeUsers = new WeakSet();
activeUsers.add(users[0]);
activeUsers.add(users[2]);

users.splice(1, 1); // Remove Miguel

let count = 0;
for (const user of users) {
if (activeUsers.has(user)) count++;
}

console.log(count);
❀5πŸ”₯2
✌️ Driver.js: Tours, Highlights, Contextual Help, and More

A vanilla JS library for making on-page tours and contextual help systems. It’s been around for several years, but is still maintained, and there are lots of examples to check out – it’s really smooth.

Kamran Ahmed
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘3❀2πŸ”₯2
CHALLENGE

function mystery() {
try {
console.log('A');
throw new Error('Oops');
console.log('B');
} catch (err) {
console.log('C');
return 'D';
} finally {
console.log('E');
return 'F';
}
console.log('G');
return 'H';
}

console.log(mystery());
❀5
🀣6πŸ‘3❀2πŸ€”2
🌲 You Don’t Know Node.js EventLoop

The Ultimate Guide to Understanding EventLoop in Node.js

This comprehensive guide is going to take some time to cover every detail that you need to know, so grab a cup of coffee and settle in for an exciting journey to the fascinating world of Node.js. Let’s get started!

nairihar
Please open Telegram to view this post
VIEW IN TELEGRAM
❀8πŸ‘2πŸ”₯2
CHALLENGE

const compose = (...fns) => x => fns.reduceRight((acc, fn) => fn(acc), x);

const addTwo = num => num + 2;
const multiplyByThree = num => num * 3;
const subtractTen = num => num - 10;

const calculate = compose(subtractTen, multiplyByThree, addTwo);

console.log(calculate(5));
❀5πŸ”₯3πŸ‘1
❀4πŸ€”3πŸ‘2
😏 CSS conditionals with the new if() function

From Chrome 137 you can try out CSS inline conditionals with the if() function. if() enables a cleaner developer interface for dynamic styles like style queries and media queries, with some key differences, which you can learn about in this post.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀10πŸ‘2πŸ”₯2
CHALLENGE

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

Vehicle.prototype.getWheels = function() {
return this.wheels;
};

function Car() {
Vehicle.call(this, 4);
this.doors = 4;
}

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

const myCar = new Car();
console.log(myCar.getWheels(), myCar instanceof Vehicle);
❀4
❀3πŸ”₯3πŸ€”3πŸ‘1