JavaScript
33K subscribers
1.14K photos
10 videos
33 files
814 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 Vehicle(type) {
this.type = type;
this.wheels = 4;
}

Vehicle.prototype.getInfo = function() {
return `${this.type} with ${this.wheels} wheels`;
};

const car = new Vehicle('sedan');
const bike = Vehicle('motorcycle');

console.log(car.getInfo());
console.log(typeof bike);
console.log(bike?.type || 'undefined');
πŸ‘6❀4πŸ”₯3
πŸ’Ž Happy 20th Birthday jQuery!

On January 14, 2006, John Resig introduced a JavaScript library called jQuery at BarCamp in New York City....

Timmy Willison
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ”₯17❀12πŸ‘10🀣1
CHALLENGE

function* innerGenerator() {
yield 1;
yield 2;
return 'inner-done';
}

function* outerGenerator() {
yield 'start';
const result = yield* innerGenerator();
yield result;
yield 'end';
}

const gen = outerGenerator();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
❀11πŸ”₯5🀣1
Whether you agree or not, Ryan Dahl, the original creator of both Node.js and Deno, drew a lot of attention for a post on X (above) where he shared a thought on the shifting roles of modern software engineers in an agentic world.
❀6πŸ‘5πŸ”₯4🀣1
CHALLENGE

function processData() {
const results = [];

for (let i = 0; i < 3; i++) {
const multiplier = i + 1;

setTimeout(() => {
results.push(i * multiplier);
}, 0);
}

setTimeout(() => {
console.log(results.join(','));
}, 10);
}

processData();
❀4πŸ‘2πŸ”₯2
What is the output?
Anonymous Quiz
20%
3,3,3
32%
0,1,2
35%
0,2,6
13%
2,4,6
πŸ”₯5πŸ‘3❀1
πŸ‘€ Superdiff 4.0: Compares Arrays or Objects and Returns a Diff

Got two similar objects or arrays and want to see the underlying differences? Superdiff has been around a while, but recent updates boost performance, add support for streamed input and using a worker for more efficient diffing in a background thread. The project now has a handy documentation site too.

antoine
Please open Telegram to view this post
VIEW IN TELEGRAM
❀9πŸ”₯4πŸ‘3
CHALLENGE

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

add(num) {
this.value += num;
return this;
}

multiply(num) {
this.value *= num;
return this;
}
}

const calc = new Calculator(5);
const addMethod = calc.add;
const result = addMethod.call(calc, 3).multiply(2);
console.log(result.value);
πŸ”₯8❀6πŸ‘4
What is the output?
Anonymous Quiz
11%
8
27%
NaN
44%
16
18%
undefined
πŸ€”5πŸ”₯3❀2πŸ‘1
CHALLENGE

class EventEmitter {
constructor() {
this.events = new Map();
}

on(event, callback) {
if (!this.events.has(event)) {
this.events.set(event, []);
}
this.events.get(event).push(callback);
return this;
}

emit(event, ...args) {
const callbacks = this.events.get(event);
if (callbacks) {
callbacks.forEach(cb => cb(...args));
}
return this;
}
}

const emitter = new EventEmitter();
emitter.on('test', x => console.log(x * 2))
.on('test', x => console.log(x + 10))
.emit('test', 5);
❀6πŸ‘3
πŸ‘7❀1
CHALLENGE

const obj = {
data: ['x', 'y', 'z'],
*[Symbol.iterator]() {
for (let i = this.data.length - 1; i >= 0; i--) {
yield this.data[i].toUpperCase();
}
}
};

const result = [];
for (const item of obj) {
result.push(item);
if (result.length === 2) break;
}

console.log(result.join('-'));
❀13πŸ‘3πŸ”₯1
What is the output?
Anonymous Quiz
41%
Z-Y
27%
x-y
12%
z-y
20%
X-Y
πŸ‘1
CHALLENGE

const x = 15;
const y = 10;
const z = 3;

const result1 = x & y;
const result2 = x | y;
const result3 = x ^ y;
const result4 = ~x;
const result5 = y << z;
const result6 = y >> 1;

console.log(`${result1},${result2},${result3},${result4},${result5},${result6}`);
πŸ”₯4❀3πŸ‘2
❀2
πŸ‘€ Introducing LibPDF: PDF Parsing and Generation from TypeScript

LibPDF bills itself as β€˜the PDF library TypeScript deserves’ and supports parsing, modifying, signing and generating PDFs with a modern API in Node, Bun, and the browser. GitHub repo.

Documenso
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ‘11❀7πŸ”₯4
CHALLENGE

const wm = new WeakMap();
let obj1 = { name: 'John' };
let obj2 = { name: 'Jane' };

wm.set(obj1, 'developer');
wm.set(obj2, 'designer');

console.log(wm.get(obj1));
console.log(wm.has(obj2));

obj1 = null;
console.log(wm.get(obj1));

const normalObj = {};
try {
wm.set('string', 'value');
} catch (e) {
console.log('error');
}
πŸ‘6πŸ”₯2