JavaScript
32.1K subscribers
1.06K photos
10 videos
33 files
734 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
Please open Telegram to view this post
VIEW IN TELEGRAM
4👍2🔥1
CHALLENGE

try {
const obj = null;
obj.property = 'value';
} catch (e) {
console.log(e.name);
}

try {
undeclaredVariable;
} catch (e) {
console.log(e.name);
}

try {
JSON.parse('invalid json');
} catch (e) {
console.log(e.name);
}
2
😆
Please open Telegram to view this post
VIEW IN TELEGRAM
1🤣485🔥4🤔1
CHALLENGE

const source = {
value: 1,
subscribers: new Set(),
subscribe(fn) {
this.subscribers.add(fn);
return () => this.subscribers.delete(fn);
},
next(newValue) {
this.value = newValue;
this.subscribers.forEach(fn => fn(this.value));
}
};

const mapped = {
value: undefined,
source,
transform: x => x * 2,
init() {
this.source.subscribe(val => {
this.value = this.transform(val);
console.log(`Mapped: ${this.value}`);
});
}
};

mapped.init();
source.next(3);
source.next(5);
console.log(`Final: ${mapped.value}`);
source.next(2);