this post was submitted on 04 Jun 2025
134 points (97.9% liked)

Programmer Humor

36167 readers
372 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 16 points 1 day ago* (last edited 1 day ago) (7 children)
('b' + 'a' + + 'a' + 'a').toLowerCase()

Returns "banana"

[–] [email protected] 5 points 1 day ago (6 children)
[–] [email protected] 0 points 1 day ago* (last edited 1 day ago) (3 children)

'a' + +

This part is the same as writing 'a'++ and that returns "NaN" (short for "not a number") since you can't increment a character, but this return type is a string, so the interpreter just concatenates it with the other letters: baNaNa. Then that string is converted to lower case to give the final result, "banana".

[–] [email protected] 3 points 1 day ago* (last edited 1 day ago)

Ironically 'a'++ works in C/C++ because 'a' is char where in JS 'a' is string.

load more comments (2 replies)
load more comments (4 replies)
load more comments (4 replies)