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 #2637 · Back to latest

Older Posts 20 shown
Post #2636 4.52K
  • ❤ 2
  • 🤔 2
Post #2635 4.41K
CHALLENGE

const obj = {
name: 'Sarah',
regularMethod: function() {
return () => {
console.log(this.name);
};
},
arrowMethod: () => {
return () => {
console.log(this.name);
};
}
};

const regular = obj.regularMethod();
const arrow = obj.arrowMethod();
regular();
arrow();
  • ❤ 6
Post #2634 4.68K
🎹 Happy Programmers Day!
  • ❤ 42
  • 🔥 12
  • 👍 7
Post #2633 4.81K
  • 🤔 9
  • ❤ 3
  • 👍 3
Post #2632 4.71K
CHALLENGE

const original = {
name: 'Emma',
skills: ['JavaScript', 'Python'],
config: { theme: 'dark', notifications: true }
};

const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));
const copy3 = Object.assign({}, original);

copy1.name = 'Sarah';
copy1.skills.push('React');
copy1.config.theme = 'light';

console.log(original.name);
console.log(original.skills.length);
console.log(original.config.theme);
  • ❤ 6
  • 🤣 6
  • 🔥 2
Post #2631 4.63K
😆
  • 🤣 45
  • 👍 6
Post #2630 4.66K
  • 👍 7
  • 🔥 6
  • ❤ 1
Post #2629 4.38K
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());
Post #2628 4.65K
  • ❤ 6
  • 👍 2
Post #2627 4.12K
CHALLENGE

const createLogger = (prefix) => (message) => `${prefix}: ${message}`;
const createCounter = () => {
let count = 0;
return () => ++count;
};

const withLogging = (fn) => (...args) => {
const result = fn(...args);
console.log(`Called with: ${args}, Result: ${result}`);
return result;
};

const counter = createCounter();
const loggedCounter = withLogging(counter);
const logger = createLogger('INFO');

console.log(loggedCounter());
console.log(logger(loggedCounter()));
  • 👍 7
  • ❤ 4
Post #2626 4.04K
😭 A Major Supply Chain Attack Hits the npm Ecosystem

In July, Socket warned us about a phishing campaign targeting npm package publishers. Sadly, a prolific package author (among others, like DuckDB, who explain how the attack worked on them) fell victim to the scam, resulting in some popular packages becoming compromised (like Chalk, debug, and others).

Gooding, Brown, et al. (Socket)
  • 🤔 4
  • 🔥 3
  • ❤ 1
Post #2625 4.05K
  • ❤ 6
  • 👍 2
Post #2624 4.2K
CHALLENGE

const original = {
name: 'Sarah',
scores: [85, 92, 78],
details: {
age: 25,
city: 'Portland'
}
};

const copy1 = { ...original };
const copy2 = JSON.parse(JSON.stringify(original));

copy1.name = 'Emma';
copy1.scores.push(95);
copy1.details.age = 30;

console.log(original.name, original.scores.length, original.details.age);
  • ❤ 7
  • 🔥 4
  • 👍 2
Post #2623 4.11K
🎨 Eyecons is a VS Code icon theme that automatically adapts the color of icons to fit your editor's main theme – well, from this list anyway.
  • 👍 9
  • ❤ 1
  • 🔥 1
Post #2622 4.45K
  • ❤ 5
  • 🔥 3
Post #2621 4.19K
CHALLENGE

class CustomError extends Error {
constructor(message) {
super(message);
this.name = 'CustomError';
}
}

try {
try {
throw new CustomError('inner error');
} catch (e) {
console.log(e.name);
throw new Error('outer error');
}
} catch (e) {
console.log(e.message);
console.log(e instanceof CustomError);
}
  • ❤ 3
Post #2620 4.17K
👀 Peaks.js 4.0: UI Component for Interacting with Audio Waveforms

A project originally spawned from the BBC’s R&D department, Peaks renders audio waveforms to a canvas element and allows scrolling, zooming, and the sort of things you might otherwise see in an audio editor. LGPL licensed.

Chris Needham et al.
  • ❤ 3
  • 👍 3
  • 🔥 3
Post #2618 4.13K
CHALLENGE

console.log('1');

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

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

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

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

Promise.resolve().then(() => {
console.log('6');
return Promise.resolve();
}).then(() => console.log('7'));

console.log('8');
  • ❤ 6
  • 👍 4
  • 🔥 4
Post #2617 4.02K
😱 Google Chrome Turns 17: A History

A fantastic walkthrough of Chrome’s origins and its evolution over the years. Addy looks at key milestones (multi-process architecture for example), security, its steps into the world of AI, and more.

Addy Osmani
  • ❤ 7
  • 👍 3
  • 🤩 3
  • 🔥 2
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 →