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
31K
Photos
1.2K
Videos
10
Links
899

Showing posts older than #1972 Β· Back to latest

Older Posts 20 shown
Post #1971 7.05K
  • 🀣 24
  • πŸ‘ 20
  • ❀ 6
Post #1970 6.71K
CHALLENGE

function displayArguments() {
console.log(arguments.length);
console.log(arguments[0]);
console.log(arguments[2]);
}

displayArguments('Hello', 'World', 'JavaScript', 'Quiz');
  • πŸ€” 8
  • 🀣 7
  • ❀ 3
  • πŸ‘ 3
  • πŸ”₯ 2
Post #1969 7.37K
πŸ“„ Play Tetris in a PDF File

I'll let you decide if this one is fun or frightening! Whether or not this will work depends on your PDF reader or browser support, but it works with Chrome and Firefox, at least.

The PDF document format supports embedded JavaScript and this experiment uses it to implement a game of Tetris. The developer, Thomas Rinsma, has used Python to output the PostScript that includes the game's JavaScript. Couple that with the fact many browser PDF renderers are themselves implemented in JavaScript (e.g. PDF.js) and you have a veritable Matryoshka doll of technologies at play here.
  • 🀣 11
  • πŸ‘ 6
  • ❀ 2
  • πŸ€” 2
Post #1968 6.08K
  • πŸ‘ 27
  • 🀣 16
  • πŸ€” 5
  • ❀ 4
  • πŸ”₯ 1
Post #1967 6.55K
CHALLENGE

function trickyFunction() {
let a = 5;
let b = '5';
let c = 5;

if (a == b && b === c) {
console.log('Condition 1');
} else if (a === c || b == c) {
console.log('Condition 2');
} else {
console.log('Condition 3');
}
}

trickyFunction();
  • πŸ‘ 6
  • πŸ”₯ 2
Post #1965 6.65K
  • 🀣 23
  • πŸ‘ 7
  • πŸ€” 7
  • ❀ 4
  • πŸ”₯ 2
Post #1964 6.64K
CHALLENGE

var obj = { a: 10, b: 20 };

with (obj) {
var result = a + b;
}

console.log(result);
  • πŸ‘ 4
  • ❀ 1
Post #1963 7.31K
⭐ 2024's JavaScript Rising Stars

It’s time to fully wave goodbye to 2024, but not before Michael Rambeau’s annual analysis of which JavaScript projects fared best on GitHub over the past year. Even if you dislike GitHub stars as a metric for anything, this remains a great way to get a feel for the JavaScript ecosystem and see what libraries and tools have mindshare in a variety of niches. A fantastic roundup as always.

Michael Rambeau
  • πŸ‘ 10
  • ❀ 2
  • πŸ”₯ 2
Post #1962 6.38K
  • ❀ 12
  • 🀣 10
Post #1961 6.79K
CHALLENGE

const myObject = {
a: 1,
b: 2,
c: 3,
[Symbol.iterator]: function* () {
for (let key of Object.keys(this)) {
yield this[key];
}
}
};

const iter = myObject[Symbol.iterator]();
console.log(iter.next().value);
console.log(iter.next().value);
console.log(iter.next().value);
  • ❀ 3
  • πŸ‘ 3
  • 🀩 1
Post #1960 7.19K
  • πŸ‘ 14
  • 🀣 14
  • ❀ 8
Post #1959 6.98K
CHALLENGE

function* customGenerator() {
yield 'Hello';
yield 'World';
return 'Done';
}

const gen = customGenerator();
console.log(gen.next().value);
console.log(gen.next().value);
console.log(gen.next().value);
  • πŸ‘ 7
  • ❀ 1
Post #1958 7.33K
  • πŸ€” 29
  • 🀣 23
  • πŸ‘ 15
  • ❀ 10
  • 🀩 1
Post #1957 7.35K
CHALLENGE

const mySet = new Set();
mySet.add(10);
mySet.add(20);
mySet.add(10);
mySet.add(30);

console.log(mySet.size);
  • πŸ‘ 13
Post #1956 7.75K
  • ❀ 7
  • πŸ‘ 6
  • πŸ”₯ 4
Post #1955 7.56K
CHALLENGE

const WM = new WeakMap();
let obj = {};
let anotherObj = {};
WM.set(obj, 'object data');
WM.set(anotherObj, 'another object data');
obj = null;

// Let's check what's logged
console.log(WM.has(obj));
console.log(WM.has(anotherObj));
  • πŸ‘ 9
  • ❀ 1
Post #1954 7.92K
😒
  • 🀣 75
  • πŸ€” 13
  • 🀩 2
Post #1953 7.02K
  • πŸ€” 16
  • πŸ‘ 14
  • 🀣 11
  • ❀ 2
  • πŸ”₯ 2
Post #1952 7.33K
CHALLENGE

async function fetchData() {
let data = 'initial';

const promise = new Promise((resolve) => {
setTimeout(() => {
resolve('fetched');
}, 1000);
});

promise.then((result) => {
data = result;
});

return data;
}

fetchData().then(console.log);
  • πŸ‘ 13
  • ❀ 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 β†’