JavaScript
31.8K subscribers
992 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
✌️ The Nginx HTTP server has a module (njs) for extending its functionality using JavaScript, but it only supported ES5. Now, njs uses QuickJS for a more modern, powerful experience with full ES2023 support.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀5πŸ”₯3πŸ‘2
CHALLENGE

function getOrder() {
console.log('1');

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

Promise.resolve().then(() => {
console.log('3');
Promise.resolve().then(() => console.log('4'));
});

Promise.resolve().then(() => console.log('5'));

console.log('6');
}

getOrder();
❀3
πŸ‘7❀4πŸ”₯3
🎹 A collection of JavaScript tools written in Rust.

The Oxidation Compiler is creating a collection of high-performance tools for JavaScript and TypeScript.
Please open Telegram to view this post
VIEW IN TELEGRAM
❀5πŸ€”2πŸ‘1πŸ”₯1
CHALLENGE

const scores = [85, 92, 78, 90];  
const student = {
name: 'Jordan',
grade: 'A',
...{ courses: ['Math', 'Science'] },
scores,
average: function() { return this.scores.reduce((a, b) => a + b) / this.scores.length }
};

const { name, ...details } = student;
const [first, ...rest] = scores;

console.log(details.scores[0], rest[0]);
❀4πŸ”₯1
πŸ”₯3πŸ‘2❀1
CHALLENGE

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

const counter = createCounter();
console.log(counter.next().value);
console.log(counter.next().value);
console.log(counter.next(true).value);
console.log(counter.next().value);
❀9πŸ‘1
πŸ‘3
CHALLENGE

function createCounter() {
let count = 0;

const counter = {
increment() {
count++;
return count;
},
getCount() {
return count;
}
};

return counter;
}

let c1 = createCounter();
c1.increment();
c1.increment();

let c2 = c1;
c1 = null;

console.log(c2.getCount());
❀3πŸ‘1
πŸ‘5πŸ€”5❀1
🀨 Laravel and Node.js: PHP in Watt Runtime

In June we featured php-node, a new way to β€˜bridge the gap’ between PHP and Node.js by being able to embed PHP into Node apps. Now they’ve gone a step further by using php-node and the Watt app server to enable the running of Laravel apps too. A curious meeting of ecosystems!

Stephen Belanger (Platformatic)
Please open Telegram to view this post
VIEW IN TELEGRAM
❀4πŸ‘1πŸ”₯1πŸ€”1
CHALLENGE

const weakSet = new WeakSet();

const obj1 = { name: 'First' };
const obj2 = { name: 'Second' };
const obj3 = obj1;

weakSet.add(obj1);
weakSet.add(obj2);

let result = '';
result += weakSet.has(obj1) + ', ';
result += weakSet.has(obj3) + ', ';

obj2.name = 'Modified';
result += weakSet.has(obj2) + ', ';

weakSet.delete(obj1);
result += weakSet.has(obj3);

console.log(result);
❀6
πŸ‘€ npq: Safely Install Packages by Auditing Them Pre-Install

npq performs several extra steps compared to npm. It consults Snyk’s database of vulnerabilities, looks at the package’s age, download count, and docs, and tries to paint a better picture of what you’re really installing.

Liran Tal
Please open Telegram to view this post
VIEW IN TELEGRAM
πŸ”₯5πŸ‘3❀1
CHALLENGE

class LightMachine {
constructor() {
this.states = {
green: { next: 'yellow' },
yellow: { next: 'red' },
red: { next: 'green' }
};
this.currentState = 'green';
}

transition() {
this.currentState = this.states[this.currentState].next;
return this.currentState;
}
}

const lightMachine = new LightMachine();
let result = '';
for (let i = 0; i < 5; i++) {
result += lightMachine.transition() + ' ';
}
console.log(result.trim());
❀2
πŸ˜‚
Please open Telegram to view this post
VIEW IN TELEGRAM
🀣48πŸ”₯4❀1πŸ‘1
CHALLENGE

async function processValues() {
try {
console.log('Start');
const a = await Promise.resolve('First');
console.log(a);
const b = await Promise.reject('Error');
console.log(b);
return 'Done';
} catch (err) {
console.log(err);
return 'Recovered';
} finally {
console.log('Finally');
}
}

processValues().then(result => console.log(result));