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
899

Showing posts older than #2314 Β· Back to latest

Older Posts 20 shown
Post #2313 4.98K
CHALLENGE

const calculator = {
value: 10,
add: function(x) {
return this.value + x;
},
multiply: function(x) {
return this.value * x;
}
};

const add5 = calculator.add;
const double = calculator.multiply.bind(calculator);
const triple = calculator.multiply.bind({value: 3});

console.log(add5(2) + double(3) + triple(4));
  • ❀ 2
  • πŸ‘ 2
Post #2311 5.25K
  • ❀ 5
  • πŸ‘ 5
  • πŸ”₯ 3
Post #2310 5K
CHALLENGE

const obj = {
name: 'Original',
greet() {
return function() {
console.log(`Hello, ${this.name}`);
};
},
arrowGreet() {
return () => {
console.log(`Hello, ${this.name}`);
};
}
};

const globalThis = { name: 'Global' };
const newObj = { name: 'New' };

const regularFn = obj.greet();
const arrowFn = obj.arrowGreet();

regularFn.call(newObj);
  • ❀ 5
  • πŸ‘ 4
  • 🀩 2
Post #2309 4.79K
😁 k6 1.0: Go-Powered Load Testing with JavaScript

A full-featured, configurable load generation tool that uses the Sobek Go-powered JavaScript engine to support writing test scripts in JavaScript. v1.0 promises stability, first-class TypeScript support, and better extensibility.

Grafana Labs
  • πŸ‘ 6
  • πŸ”₯ 2
  • ❀ 1
Post #2308 4.98K
  • πŸ‘ 3
  • πŸ”₯ 3
  • ❀ 2
  • 🀣 1
Post #2307 5.02K
CHALLENGE

function processData(data) {
try {
if (!data) {
throw new TypeError('Data is required');
}

if (data.status === 'error') {
throw new Error('Invalid status');
}

return data.value.toUpperCase();
} catch (err) {
if (err instanceof TypeError) {
return 'Type Error';
}
return err.message;
}
}

console.log(processData({ status: 'error', value: 'test' }));
  • ❀ 5
Post #2306 4.91K
  • πŸ‘ 7
  • 🀩 3
  • ❀ 1
Post #2305 4.98K
CHALLENGE

const team = {
members: ['Alice', 'Bob', 'Charlie'],
leader: 'Diana',
[Symbol.iterator]: function*() {
yield this.leader;
for(const member of this.members) {
yield member;
}
}
};

let names = [];
for (const person of team) {
names.push(person);
}

console.log(names.join(', '));
  • ❀ 7
  • πŸ‘ 2
Post #2304 4.93K
  • ❀ 4
  • πŸ‘ 4
  • πŸ”₯ 3
Post #2303 5.1K
CHALLENGE

const obj = {};
const sym1 = Symbol('description');
const sym2 = Symbol('description');

obj[sym1] = 'Value 1';
obj[sym2] = 'Value 2';
obj.regularProp = 'Regular';

const allKeys = Object.getOwnPropertySymbols(obj).length + Object.keys(obj).length;
const comparison = sym1 === sym2;

console.log(allKeys + ',' + comparison);
  • ❀ 4
  • πŸ‘ 3
  • πŸ”₯ 1
Post #2302 5.17K
  • πŸ‘ 5
  • ❀ 2
  • πŸ”₯ 1
  • 🀩 1
Post #2301 5.11K
CHALLENGE

const inventory = {
items: ['apple', 'banana', 'orange'],
[Symbol.iterator]: function() {
let index = 0;
const items = this.items;

return {
next: function() {
return index < items.length ?
{ value: items[index++].toUpperCase(), done: false } :
{ done: true };
}
};
}
};

const result = [...inventory].join(' + ');
console.log(result);
  • ❀ 4
  • πŸ‘ 4
  • πŸ”₯ 1
Post #2299 5.16K
  • ❀ 3
  • πŸ€” 1
Post #2298 5.06K
CHALLENGE

const target = { name: 'Alice' };

const handler = {
get(obj, prop) {
return prop in obj ? obj[prop].toUpperCase() : 'NOT_FOUND';
},
set(obj, prop, value) {
if (typeof value !== 'string') {
return false;
}
obj[prop] = value.trim();
return true;
}
};

const proxy = new Proxy(target, handler);
proxy.name = ' Bob ';
proxy.age = 30;

console.log(`${proxy.name}-${proxy.age}-${proxy.job}`);
  • πŸ‘ 9
Post #2297 4.63K
🀩 PDFSlick 3.0: View and Interact with PDF Documents in JS Apps

A full-featured PDF viewer for React, Solid, Svelte and vanilla JS apps. Built on top of PDF.js, it offers a wide array of features from simple PDF viewing to working with multiple and large documents with annotations. Demo. v3.0 bumps up to PDF.js v5 with ICC profile support, better JPEG 2000 support, and improved rendering of large pages.

Vancho Stojkov
  • πŸ‘ 4
  • πŸ”₯ 2
  • ❀ 1
  • 🀩 1
Post #2296 4.64K
  • πŸ‘ 9
  • ❀ 2
  • πŸ”₯ 2
Post #2295 4.98K
CHALLENGE

const obj = {
value: 42,
getValue() {
return this.value;
},
getArrowValue: () => {
return this.value;
},
getDelayedValue() {
setTimeout(function() {
console.log(this.value);
}, 0);
},
getFixedDelayedValue() {
setTimeout(() => {
console.log(this.value);
}, 0);
}
};

obj.getDelayedValue();
  • ❀ 4
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 β†’