TGViewer
Channel Public Channel
JavaScript

JavaScript

@javascript

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
Subscribers
31.1K
Photos
1.2K
Videos
10
Links
895

Showing posts older than #2799 · Back to latest

Older Posts 20 shown
Post #2798 3.88K
CHALLENGE

console.log('1');

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

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

queueMicrotask(() => console.log('4'));

setTimeout(() => {
console.log('5');
Promise.resolve().then(() => console.log('6'));
}, 0);

console.log('7');
  • ❤ 2
Post #2796 3.63K
  • ❤ 4
  • 🤔 2
  • 👍 1
Post #2795 3.65K
CHALLENGE

const target = { name: 'Sarah', age: 25 };
const handler = {
get(obj, prop) {
if (prop === 'info') {
return `${obj.name} is ${obj.age}`;
}
return Reflect.get(obj, prop);
},
has(obj, prop) {
return prop !== 'age' && Reflect.has(obj, prop);
}
};
const proxy = new Proxy(target, handler);
console.log(proxy.info);
console.log('age' in proxy);
console.log('name' in proxy);
  • ❤ 3
  • 🤔 1
Post #2793 3.49K
  • 🤣 5
  • ❤ 3
  • 👍 1
Post #2792 3.57K
CHALLENGE

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

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

const keys = [];
for (let key of wm) {
keys.push(key);
}

console.log(keys.length);
console.log(wm.has(obj1));
console.log(wm.get(obj2));
Post #2791 3.77K
🤩 The Inner Workings of JavaScript Source Maps

Ever wondered how devtools can magically turn mangled, minified JavaScript back into readable source while debugging? Zero magic; that’s a source map doing its job. But how do source maps actually work under the hood?

Manoj Vivek
  • ❤ 3
  • 👍 3
  • 🔥 1
Post #2790 3.56K
  • 👍 6
  • ❤ 4
  • 🤔 1
Post #2789 3.44K
CHALLENGE

const user = { name: 'Sarah', age: 28 };
const greeting = 'Hello';
const template = `${greeting}, ${user.name}! You are ${user.age} years old.`;

function createMessage(strings, ...values) {
return strings.reduce((result, string, i) => {
return result + string + (values[i] ? `[${values[i]}]` : '');
}, '');
}

const tagged = createMessage`Welcome ${user.name}, age: ${user.age}!`;
console.log(template);
console.log(tagged);
  • ❤ 6
  • 🔥 1
Post #2787 3.91K
  • 🤣 9
  • ❤ 4
  • 👍 2
Post #2786 3.72K
CHALLENGE

const data = '{"name":"Sarah","age":25,"skills":["JavaScript","Python"]}'
const parsed = JSON.parse(data)
const stringified = JSON.stringify(parsed, null, 0)
const reparsed = JSON.parse(stringified)

try {
const invalid = '{name:"John","incomplete":}'
JSON.parse(invalid)
} catch (e) {
console.log(e.name)
}

console.log(typeof parsed.age)
console.log(reparsed.skills.length)
console.log(JSON.stringify({a: undefined, b: null, c: 0}))
  • ❤ 1
Post #2785 3.89K
😮 Render.js: A Raytracing Renderer with RenderMan Format Support

Created at Pixar in the 80s, the RenderMan Interface Specification was an early API for building 3D scenes. Anders has been building a Node-based, 90s-style renderer for the format “as a stroll down amnesia lane” in pure JavaScript.

Anders Brownworth
  • ❤ 2
  • 👍 2
  • 🔥 2
  • 🤩 1
Post #2783 4.45K
  • ❤ 9
  • 👍 3
  • 🤔 3
Post #2782 4.43K
CHALLENGE

const obj = { count: 0 };
const arr = [obj, obj, obj];

function increment(item) {
item.count++;
return item;
}

const results = arr.map(increment);
console.log(obj.count);
console.log(results[0] === results[1]);
console.log(results.length);
console.log(arr[0].count);
  • ❤ 7
Post #2781 4.47K
🤟 Node.js Security Best Practices

Did you know the Node.js project maintains a page about security best practices organized around how to mitigate ten of the most significant vectors? Topics include networking weaknesses, timing attacks, supply chain attacks, and the monkey patching of intrinsics.

Node Documentation
  • ❤ 3
  • 👍 1
  • 🔥 1
Post #2780 3.8K
  • 👍 3
  • ❤ 2
  • 🔥 1
Post #2779 3.78K
CHALLENGE

class EventEmitter {
constructor() {
this.events = {};
}

on(event, callback) {
this.events[event] = this.events[event] || [];
this.events[event].push(callback);
return this;
}

emit(event, data) {
if (this.events[event]) {
this.events[event].forEach(cb => cb(data));
}
return this;
}
}

class Logger {
log(msg) { console.log(`[LOG]: ${msg}`); }
}

class DataProcessor {
constructor(emitter, logger) {
this.emitter = emitter;
this.logger = logger;
this.emitter.on('process', (data) => {
this.logger.log(data.toUpperCase());
});
}

process(data) {
this.emitter.emit('process', data);
}
}

const emitter = new EventEmitter();
const logger = new Logger();
const processor = new DataProcessor(emitter, logger);

processor.process('hello world');
emitter.emit('process', 'composition rocks');
  • 👍 4
  • ❤ 3
Older posts →
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →