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
Post #2941
3.06K
- 🔥 5
- 👍 3
- ❤ 1
JA @javascript
Showing posts older than #2942 · Back to latest
function processData() {
const results = [];
for (let i = 0; i < 3; i++) {
const multiplier = i + 1;
setTimeout(() => {
results.push(i * multiplier);
}, 0);
}
setTimeout(() => {
console.log(results.join(','));
}, 10);
}
processData();
function* innerGenerator() {
yield 1;
yield 2;
return 'inner-done';
}
function* outerGenerator() {
yield 'start';
const result = yield* innerGenerator();
yield result;
yield 'end';
}
const gen = outerGenerator();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
function Vehicle(type) {
this.type = type;
this.wheels = 4;
}
Vehicle.prototype.getInfo = function() {
return `${this.type} with ${this.wheels} wheels`;
};
const car = new Vehicle('sedan');
const bike = Vehicle('motorcycle');
console.log(car.getInfo());
console.log(typeof bike);
console.log(bike?.type || 'undefined');
function mysteryFunction() {
console.log(x);
console.log(y);
console.log(z);
var x = 'declared';
let y = 'block-scoped';
const z = 'constant';
console.log(x);
console.log(y);
console.log(z);
}
mysteryFunction();
--require-modulehttp.setGlobalProxyFromEnv() addedconst obj = {
value: 42,
[Symbol.toPrimitive](hint) {
if (hint === 'number') return this.value * 2;
if (hint === 'string') return `Value: ${this.value}`;
return this.value + 10;
}
};
console.log(+obj);
console.log(`${obj}`);
console.log(obj + 5);
console.log(Number(obj));
const numbers = [1, 2, 3, 4, 5, 6];
const result = numbers
.map(x => x * 2)
.filter(x => x > 6)
.reduce((acc, x) => {
console.log(`Processing ${x}, acc: ${acc}`);
return acc + x;
}, 0);
console.log(`Final result: ${result}`);
