An Interest In:
Web News this Week
- March 30, 2024
- March 29, 2024
- March 28, 2024
- March 27, 2024
- March 26, 2024
- March 25, 2024
- March 24, 2024
A few JavaScript puzzlers
Cover photo by Kyle Glenn on Unsplash.
Good morning! How's your weekend going?
I've been sick lately, so haven't had a lot of energy to work on the usual posts. But I've put together a few quick "riddles" specific to JavaScript.
If you get the answers early on, try to not spoil the answers in the comments for those just looking for hints rather than solutions. (Spoiler tags when?)
#1 - Non-reflexive
This one is fairly simple if you know the language "gotchas", but quite a puzzle indeed if you've never seen this behavior before.
x === x; // truex[+[]] === x[+[]]; // false
There is more than one answer, see if you can find the whole solution space for an additional challenge.
Hint links:
#2 - Reciprocal
Here's another head scratcher:
x === y; // true1/x === 1/y; // false
Find values of x & y.
The senior JS devs are groaning and probably already know the answer. But for those of you less practiced, here is a hint:
#3 - Prototype
And another one:
var someone = function() {};someone.prototype.attributes = {};var alice = new someone();alice.attributes.name = 'Alice';var bob = new someone();bob.attributes.name = 'Bob';var eve = new someone();
At the end of this code, what is eve.attributes.name
?
Your hints are:
JavaScript really is quite a puzzling language, isn't it? Which ones did you get immediately, and which did you need to look up?
Have a great weekend, and don't forget to be awesome!
Original Link: https://dev.to/tchaflich/a-few-javascript-puzzlers-2p1l
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To