Logo
CTRL+C, CTRL+V: The real programming heroes.
  • 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 Webdev Frontend
9 months ago 306.4K 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

Dell UltraSharp 34 Curved Thunderbolt Hub Monitor - U3426WER

Dell UltraSharp 34 Curved Thunderbolt Hub Monitor - U3426WER

Affiliate
$1049.99
AI Companies Right Now

AI Companies Right Now

AI
13.3M views 3 months ago
I'm an expert hello-world developer!

I'm an expert hello-world developer!

Programming
96.7K views 2 years ago