JavaScript
32.1K subscribers
1.06K photos
10 videos
33 files
737 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
And there is another fork 😆
Please open Telegram to view this post
VIEW IN TELEGRAM
🤣9
CHALLENGE

const user = {
profile: {
settings: {
theme: 'dark'
}
}
};

const getTheme = (obj) => obj?.profile?.settings?.theme ?? 'light';
const getLanguage = (obj) => obj?.profile?.settings?.language ?? 'en';
const getNotifications = (obj) => obj?.profile?.notifications?.enabled ?? true;

console.log(getTheme(user));
console.log(getLanguage(user));
console.log(getNotifications(user));
console.log(getTheme(null));
2
CHALLENGE

const moduleMap = new Map();

async function loadModule(name) {
if (moduleMap.has(name)) {
return moduleMap.get(name);
}

const module = await Promise.resolve({
default: () => `Module ${name} loaded`,
version: '1.0.0'
});

moduleMap.set(name, module);
return module;
}

loadModule('auth').then(m => console.log(m.default()));
loadModule('auth').then(m => console.log(m.version));
loadModule('db').then(m => console.log(m.default()));
3👍1
CHALLENGE

function createCounter() {
let count = 0;
return {
increment: () => ++count,
decrement: () => --count,
getValue: () => count
};
}

const counter1 = createCounter();
const counter2 = createCounter();
counter1.increment();
counter1.increment();
counter2.increment();
console.log(counter1.getValue(), counter2.getValue());
counter1.decrement();
console.log(counter1.getValue(), counter2.getValue());
5🤩1
What is the output?
Anonymous Quiz
20%
1 1 0 0
33%
2 1 1 0
37%
2 1 1 1
10%
3 2 2 1
8
CHALLENGE

const wm = new WeakMap();
const obj1 = { name: 'first' };
const obj2 = { name: 'second' };
const obj3 = obj1;

wm.set(obj1, 'value1');
wm.set(obj2, 'value2');
wm.set(obj3, 'value3');

console.log(wm.get(obj1));
console.log(wm.get(obj2));
console.log(wm.get(obj3));
console.log(wm.has(obj1));
console.log(wm.size);
3👍1