Logo
Only three hard problems: cache, naming, and off-by-one errors.
  • Home
  • Hot
  • Random
  • Search

Browse

  • AI AI
  • AWS AWS
  • Agile Agile
  • Algorithms Algorithms
  • Android Android
  • Apple Apple
  • Azure Azure
  • Backend Backend
  • Bash Bash
  • C++ C++
  • Cloud Cloud
  • All Categories
As an Amazon Associate ProgrammerHumor.io earns from qualifying purchases.

HTTP 418: I'm a teapot

The server identifies as a teapot now and is on a tea break, brb

HTTP 418: I'm a teapot

The server identifies as a teapot now and is on a tea break, brb

Negative-indexing Memes

Posts tagged with Negative-indexing

JS Is A Very Respectable Language

Javascript Frontend Webdev
11 months ago 335.3K views 1 shares
JS Is A Very Respectable Language
JavaScript really said "consistency is for COWARDS" and honestly? It committed to the bit. 💀 So you've got an array [1, 2, 3] and you're like "hey what's at index -2?" JavaScript casually returns undefined because negative indices don't exist in JS arrays... EXCEPT when you use .at(-2) which is specifically designed to handle negative indices and suddenly it's like "oh you want the second element from the end? Here's your 2, bestie!" Then you assign foo[-2] = 4 which JavaScript happily accepts because arrays are objects and you just created a STRING property called "-2" on that array object. So now foo[-2] returns 4 from the object property while foo.at(-2) STILL returns 2 from the actual array position. Same syntax, completely different universes. Very respectable. Very normal. Nothing to see here. 🎪

Today's picks

Panvola There Is No Place Like 127.0.0.1 Programmer Gifts For Husband Boyfriend Brother Localhost Coder IT Programming Students Teacher Software Engineer Gifts Ceramic Mug 11 oz White

Panvola There Is No Place Like 127.0.0.1 Programmer Gifts For Husband Boyfriend Brother Localhost Coder IT Programming Students Teacher Software Engineer Gifts Ceramic Mug 11 oz White

Affiliate
$12.97
NordVPN

NordVPN

Sponsored
VPN
I’m not a robot*

I’m not a robot*

Programming
131.2K views 5 years ago