JavaScript
32.1K subscribers
1.05K photos
10 videos
33 files
726 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

const userInput = "<script>alert('xss')</script>";
const sanitized = userInput
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#x27;');

const credentials = {
username: 'admin',
password: 'secret123'
};

const safeLog = (obj) => {
const { password, ...safe } = obj;
return JSON.stringify(safe);
};

console.log(sanitized);
console.log(safeLog(credentials));
3🔥3👍1
CHALLENGE

const wm = new WeakMap();
const obj1 = {};
const obj2 = {};
const obj3 = obj1;

wm.set(obj1, 'first');
wm.set(obj2, 'second');
wm.set(obj3, 'third');

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