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 #2091
6.04K
- π€ 30
- π 16
- β€ 2
- π₯ 2
JA @javascript
Showing posts older than #2092 Β· Back to latest
function trickyFunction(num) {
let result = 0;
for (let i = 0; i < num; i++) {
result += i;
if (i % 2 === 0) {
result *= 2;
} else {
result -= 1;
}
}
return result;
}
console.log(trickyFunction(4));
function trickyScope() {
var a = 10;
let b = 20;
const c = 30;
if (true) {
var a = 40;
let b = 50;
const c = 60;
console.log(a, b, c);
}
console.log(a, b, c);
}
trickyScope();function trickyScope() {
var x = 10;
if (true) {
let x = 5;
console.log(x);
}
console.log(x);
}
trickyScope();
const sym1 = Symbol('description');
const sym2 = Symbol('description');
const obj = {
[sym1]: 'value1',
[sym2]: 'value2'
};
console.log(obj[sym1]);const numbers = [1, 2, 3, 4, 5];
const result = numbers
.filter(num => num % 2 === 0)
.map(num => num * num)
.reduce((acc, num) => acc + num, 0);
console.log(result);



let person = {
name: 'Alice',
age: 30,
valueOf: function() {
return this.age;
}
};
let result = person + 10;
console.log(result);