31615
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
🤨 ANSIS 4.0: ANSI Color Library for Everywhere
A library to use the power of ANSI escape sequences for coloring and styling text in many environments including the terminal, Chromium-based browsers, Node, Bun, Deno, and even Next.js. v4.0 is a big upgrade with enough breaking changes to warrant a migration guide for existing users.
webdiscus
🙏 To continue delivering more exciting stories, we're kindly asking telegram premium users to help us (boost) take things to the next level.
We need 40 boosts 😭
/channel/javascript?boost
🤔 I Think the Ergonomics of Generators is Growing on Me
The author notes generator functions have been widely available in JavaScript for a long time, yet “their practicality hasn’t exactly caught on.” This is a great look at what they are and where they can be useful.
Alex MacArthur
CHALLENGE
function modify(obj) {
obj.a.push(4);
obj.b = 'changed';
return obj;
}
const original = { a: [1, 2, 3], b: 'original', c: { deep: true } };
const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));
modify(copy1);
console.log(original.a, original.b, copy2.c === original.c);
Читать полностью…
🥶 Write Github Actions workflow files in TypeScript (compiles to YAML)
emmanuelnk
🤟 To ensure your Node.js version is secure, use:
npx is-my-node-vulnerable
🥂 We Did It – 25K Subscribers!
We're excited to announce that our newsletter reached 25,000 subscribers! This was one of our biggest goals for 2024, and we couldn’t have done it without your amazing support.
Thank you for being part of this journey. We’ve got more exciting content coming, so stay tuned!
CHALLENGE ❓
Читать полностью…
const map = new Map();
const key1 = {};
const key2 = key1;
map.set(key1, "Value for key1");
map.set(key2, "Value for key2");
console.log(map.get({}));
console.log(map.get(key1));
CHALLENGE ❓
Читать полностью…
const obj = {};
Object.defineProperty(obj, 'name', {
value: 'Alice',
writable: false,
configurable: false
});
try {
obj.name = 'Bob';
delete obj.name;
console.log(obj.name);
} catch (e) {
console.log('Error:', e.message);
}
CHALLENGE ❓
Читать полностью…
function processData({ a = 10, b = 20 } = { a: 30 }) {
console.log(a, b);
}
processData({ a: 5 });
processData();
CHALLENGE ❓
Читать полностью…
function* numberGenerator() {
let i = 0;
while (i < 3) {
yield i++;
}
}
const gen = numberGenerator();
console.log(gen.next().value);
console.log(gen.return(10).value);
console.log(gen.next().value);
CHALLENGE ❓
Читать полностью…
const obj = Object.freeze({
name: "Alice",
info: {
age: 25
}
});
try {
obj.name = "Bob";
obj.info.age = 30;
} catch (e) {
console.log("Error:", e.message);
}
console.log(obj.name, obj.info.age);
CHALLENGE ❓
Читать полностью…
async function first() {
console.log('First Start');
await second();
console.log('First End');
}
async function second() {
console.log('Second Start');
}
console.log('Script Start');
first();
setTimeout(() => console.log('Timeout'), 0);
console.log('Script End');
CHALLENGE ❓
Читать полностью…
setTimeout(() => console.log('Timeout 1'), 100);
setTimeout(() => {
console.log('Timeout 2');
Promise.resolve().then(() => console.log('Promise in Timeout 2'));
}, 50);
Promise.resolve().then(() => console.log('Promise 1'));
setTimeout(() => console.log('Timeout 3'), 150);
console.log('Sync');
CHALLENGE
try {
const arr = [1, 2, 3];
function processArray() {
try {
nonExistentFunction();
} catch (err) {
throw new TypeError('Invalid type');
}
}
try {
processArray();
} catch (err) {
console.log(err instanceof Error, err instanceof TypeError, err.message);
}
} catch (finalError) {
console.log('Caught in outer block:', finalError);
}
Читать полностью…
🥃 We often get feedback asking us to include answers to the quizzes—but honestly, some of them need more explanation than a Marvel movie plot. It’s way better if you use Google or GPT to dig into the questions and uncover the answers like the true quiz detective you are!
Читать полностью…
CHALLENGE
const result = (function() {
let count = 0;
return {
increment() {
return ++count;
},
get value() {
return count;
},
reset() {
const oldCount = count;
count = 0;
return oldCount;
}
};
})();
result.increment();
result.increment();
console.log(result.reset() + result.value + result.increment());
Читать полностью…
CHALLENGE
function processTransaction(amount) {
try {
if (typeof amount !== 'number') {
throw new TypeError('Amount must be a number');
}
if (amount <= 0) {
throw new RangeError('Amount must be positive');
}
return 'Transaction processed';
} catch (error) {
if (error instanceof TypeError) {
return { status: 'Type Error', message: error.message };
} else if (error instanceof RangeError) {
return { status: 'Range Error', message: error.message };
}
return { status: 'Unknown Error', message: error.message };
}
}
console.log(processTransaction(-50));
Читать полностью…
CHALLENGE
Читать полностью…
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 100);
}
CHALLENGE ❓
Читать полностью…
const sym = Symbol('unique');
const obj = {
[sym]: 'Secret',
public: 'Visible'
};
console.log(Object.keys(obj));
console.log(obj[Symbol('unique')]);
CHALLENGE ❓
Читать полностью…
Promise.resolve(1)
.then(value => {
console.log(value);
throw new Error('Something went wrong');
})
.then(() => {
console.log('This will not run');
})
.catch(error => {
console.log('Caught:', error.message);
return 42;
})
.then(value => {
console.log('Recovered with:', value);
});
👀 The Story of Web Framework Hono, By Its Creator
Hono is a neat, lightweight framework designed to run on any JavaScript runtime that has been picking up steam in the past year. You can create a simple app reminiscent of Express.js, say, but run it on Cloudflare Workers, Deno, Bun, or Node. It’s in heavy use all over the place, and has lots of interesting features like letting you write HTML with JSX.
Yusuke Wada
🤟 Node v20.18.0 (LTS) Released; v20 'Iron' Prepares to Bow Out as Active LTS Release
It’s been a quiet few weeks for official releases. This update marks one of the last in Node 20’s run as the active LTS release, and introduces experimental network inspection support. Node 22 will soon take over the active LTS crown (as per schedule) but what will its codename be given there are no elements starting with J? Amazingly, this question was asked six years ago and it's (probably) going to be Jod.
Michaël Zasso
✌️ 10 New JS Features You Should Know About
Awesome
💻 Does Deno 2 really uncomplicate JavaScript?
Beyond Fireship
👀 DOCX 9.0: Generate Word .docx Files from JavaScript
The code to lay out documents is verbose but there’s a lot of functionality baked in and there aren’t many other options for this task. Here’s a CodePen-based example to give you an idea. GitHub repo.
Dolan Miu
✌️ TC39 Advances 10+ ECMAScript Proposals
The architects behind the development of the ECMAScript / JavaScript spec got together again this week (you can see them in this tweet) and they had a packed agenda. Import attributes, Iterator helpers, Promise.try and Regexp modifiers all made it to stage 4, and more besides.
Sarah Gooding (Socket)
CHALLENGE ❓
Читать полностью…
setTimeout(() => {
console.log('Timeout');
Promise.resolve().then(() => console.log('Promise after Timeout'));
}, 0);
Promise.resolve().then(() => console.log('Promise'));
console.log('End of script');