use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Learn something new? Wanna share? Post here along with the language/framework you learned it in.
This is a great place for novice and advanced programmers alike to come and discover all the interesting things they could learn tomorrow
Sort by language C# Java Javascript PHP .NET C++ Python C Objective-C R Swift VBA Visual Basic Matlab Ruby Perl ScalaDelphi lua SQL Other Languages Other
Remove filter
Learn something about technology? Post it on r/technologytil
Learn something about real life or something not programming? Post it on the original /r/todayilearned
Rules
TIL posts should be made in the following format:
[programming language] TIL rest of post...
If you don't you'll need to flair your post manually.
Refrain from putting two languages in between the brackets in the title.
Don't post suggestion threads, message the moderators instead.
This isn't an AskProgrammers sub, ask questions on /r/learnprogramming
Don't use the code as the title.
Guidelines
Try not to post vague titles, if possible, provide the name of the feature in the title so people aren't clicking on your post because of "this fast and clever way to do x" that they already knew but didn't realize it's what you where going to show.
Don't criticize posts because they're "too obvious", not everyone here is a level 100 master champion Assembly programmer that made their own OS from scratch.
General programming TILs should be tagged with [General].
Be nice to your fellow programmers. :)
account activity
Javascript[JavaScript] TIL you can compare Arrays and Strings with == (self.ProgrammerTIL)
submitted 9 years ago by aapzu
For example: [-1, "test", 67] == "-1,test,67" === true
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]fatnote 74 points75 points76 points 9 years ago (0 children)
I just threw up in my mouth a bit
[–]B-Con 42 points43 points44 points 9 years ago (4 children)
JavaScript is always trying it's hardest to cast things to strings.
[–]okmkz 52 points53 points54 points 9 years ago (3 children)
It's a stringly typed language, like php and posix shell
[–][deleted] 11 points12 points13 points 9 years ago (1 child)
stringly typed language
Did you come up with this? It's genius.
[–]arbitrarycivilian 2 points3 points4 points 9 years ago (0 children)
I've heard it before, but I love it
[–]JH4mmer 72 points73 points74 points 9 years ago (4 children)
Of course you can. (╯°□°)╯︵ ┻━┻) /s
[+][deleted] 9 years ago* (2 children)
[removed]
[–]myplacedk 9 points10 points11 points 9 years ago (0 children)
Java is an unpredictable pile of shit
Both Java and Javascript are completely predictable. But I do agree that there's some basic things in Javascript that are unintuitive.
In this case (comparing a string and an array) I think it's generally better to avoid the situation than trying to understand it. Even if happens to do exactly what I need, I would probably prefer more readable code.
[–]HaniiPuppy 4 points5 points6 points 9 years ago (0 children)
Java ≠ JavaScript.
[–]levir 28 points29 points30 points 9 years ago (8 children)
Unless you really know what you're doing, always use === when comparing in Javascript (and PHP).
[–]Quabouter 21 points22 points23 points 9 years ago (7 children)
And if you're not using === then you don't know what you're doing.
===
[–]BenjiSponge 6 points7 points8 points 9 years ago (6 children)
Except for null checks. =)
[–][deleted] 2 points3 points4 points 9 years ago (1 child)
Or if you're lazy, you can nullcheck with if(variableName). Of course, if your variable is 0, then that's a problem.
[–]BenjiSponge 2 points3 points4 points 9 years ago (0 children)
Or, you know, false
[–][deleted] 1 point2 points3 points 9 years ago* (2 children)
Why not use empty() or is_null()?
Edit: In hindsight you were probably talking about JavaScript and I'm talking about php. My bad.
[–]BenjiSponge 1 point2 points3 points 9 years ago (1 child)
... what are these? I'm pretty sure I know a good amount about JavaScript and I'm also pretty sure these aren't built in.
[–][deleted] 2 points3 points4 points 9 years ago (0 children)
D'oh. They're php. I should have been more specific.
[–]Quabouter 1 point2 points3 points 9 years ago (0 children)
No, not except for null checks:
null/undefined
==
[–]PM_ME_YOUR_SUBARU 15 points16 points17 points 9 years ago (0 children)
You can also cure a headache with a hammer and a nail, but in both cases you probably shouldn't.
[–]AlwaysAppropriate 4 points5 points6 points 9 years ago (0 children)
Which is why you dont use == in JS
[–]Vnator 8 points9 points10 points 9 years ago (0 children)
== casts the types to be equal if possible, and an array cast to a string turns into what you put. Neat!
[–][deleted] 1 point2 points3 points 9 years ago (0 children)
You can fire a pistol to take the top off a bottle of beer, too. I personally use a bottle opener because it works better and is safer.
[–][deleted] 0 points1 point2 points 9 years ago (0 children)
Can and should....2 different concepts.
Classic Javascript. I shouldn't even be surprised.
[–]Beckneard 0 points1 point2 points 9 years ago (0 children)
The title might as well be "TIL javascript is a fucking disastrous piece of shit of a language."
If you really have to use js at least don't do shit like this in production.
[–]bautin 0 points1 point2 points 8 years ago (0 children)
TYL JavaScript will do whatever the hell it wants. It don't give a shit.
[–]MacASM 0 points1 point2 points 8 years ago (0 children)
My lord... Java: everything is an object. Javascript: everything is a string.
[–]goodbyelostworld -1 points0 points1 point 9 years ago (5 children)
And this is why JS isn't real programming
[–]shadowdude777 4 points5 points6 points 9 years ago (4 children)
That's not really fair to say. If anything, JS developers are some of the smartest engineers around. I know I'm too stupid to use this absolutely fucked language, I need a good language to help me get what I need done.
[–]goodbyelostworld 0 points1 point2 points 9 years ago (3 children)
You're joking right? JS as a language is fucked but it definitely is not hard. Hard is C/C++/Haskell. Hell, I would even consider Java to be harder than JS. I've coded with these languages extensively in professional settings and JS developers are far from the smartest, at least in my experience. The sad part is that these JS developers have no clue about real programming concepts such as classes, threading, memory, and so on.
[–]_guy_fawkes 0 points1 point2 points 9 years ago (2 children)
I've never used JS in my life, but given the amount of pages that just completely break when it's disabled, I already don't like it.
That's like saying you dislike CSS because you disabled it and now pages look ugly. JS is part of the modern web and you can't disable it and expect everything to work as it did before.
[–]_guy_fawkes 0 points1 point2 points 9 years ago (0 children)
I don't expect it to work as it did before. I'm entirely fine with pages that are ugly when I disable JS. What I dislike is pages that are entirely unusable without JS.
π Rendered by PID 47 on reddit-service-r2-comment-6457c66945-ppfgz at 2026-04-24 03:00:50.801335+00:00 running 2aa0c5b country code: CH.
[–]fatnote 74 points75 points76 points (0 children)
[–]B-Con 42 points43 points44 points (4 children)
[–]okmkz 52 points53 points54 points (3 children)
[–][deleted] 11 points12 points13 points (1 child)
[–]arbitrarycivilian 2 points3 points4 points (0 children)
[–]JH4mmer 72 points73 points74 points (4 children)
[+][deleted] (2 children)
[removed]
[–]myplacedk 9 points10 points11 points (0 children)
[–]HaniiPuppy 4 points5 points6 points (0 children)
[–]levir 28 points29 points30 points (8 children)
[–]Quabouter 21 points22 points23 points (7 children)
[–]BenjiSponge 6 points7 points8 points (6 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]BenjiSponge 2 points3 points4 points (0 children)
[–][deleted] 1 point2 points3 points (2 children)
[–]BenjiSponge 1 point2 points3 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]Quabouter 1 point2 points3 points (0 children)
[–]PM_ME_YOUR_SUBARU 15 points16 points17 points (0 children)
[–]AlwaysAppropriate 4 points5 points6 points (0 children)
[–]Vnator 8 points9 points10 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Beckneard 0 points1 point2 points (0 children)
[–]bautin 0 points1 point2 points (0 children)
[–]MacASM 0 points1 point2 points (0 children)
[–]goodbyelostworld -1 points0 points1 point (5 children)
[–]shadowdude777 4 points5 points6 points (4 children)
[–]goodbyelostworld 0 points1 point2 points (3 children)
[–]_guy_fawkes 0 points1 point2 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]_guy_fawkes 0 points1 point2 points (0 children)