the hardest exam question
the hardest exam question
the hardest exam question
If you're living in 2002 and not using the strict equality operator, that's on you
But what if I don't want strict comparison? What if my frontend contains a text field for a numeric input and I wanna manually check against each possible valid input value if (input_val == 1) {...} else if (input_val == 2) {...} else if...
without having to convert it first or check that it's actually a number or fix my frontend?
(I'm sure there are valid use cases for non-strict comparison, I just can't think of one right now)
PHP has gotten really good over the past few versions, actually. Lots of really great stuff has been added, it feels like it resembles rust more every release lol
PHP10: We now allow interop with Rust!
PHP11: We now allow writing code directly in a .php file and compile it with rustc.
I am forced to try to get a JS certification.
I am reaching the end of my rope, and starting to think of maybe putting my neck into one.
Isaac Newton said that we see far because we stand on the shoulders of giants.
Javascript is like standing on the shoulders of dwarves with brittle bone disease.
1 - Easiest way to run a script in your browser
\
2 - Always finds its way if inputs are bad
\
Nan - undefined
NaN is of type number. because fuck me.
IEEE-754
Easiest? More like... The only way.
It leads to typescript
You get surprises from npm
You get suprises from npm
I spent way too long today figuring out why my app was doing something that it's NOT supposed to do on weekends.
I read Luxon's docs (pretty cool lib tbh) again and again, and tried everything I could think of to get isWeekend to return a sane result.
Turns out I was pulling a somewhat older version of Luxon, where isWeekend didn't exist. In any sane language, I expect I'd get a huge warning about a property that doesn't exist, but alas...
Typescript helps me keep my sanity, but juuuuust barely.
The part that always gets me is when people choose Js for the backend. Like I get that it's the default thing that works on the frontend, so there's some rationale why you might not want to transpile to it from another language. On the backend though, there are so many far better option, why would you willingly go with Js, especially given that you're now forced to do all your IO async.
Server side rendering looks like it could be useful. I imagine SSR could be used for graceful degradation, so what would normally be a single page application could work without Javascript. Though, I've never tried SSR, and nobody seems to care about graceful degradation anymore.
Most pages tend be just documents and fairly simple forms. Making SPAs and then having to worry about SSR is just making a Rube Goldberg machine in most cases. I think something like HTMX is a much better approach in most cases. You keep all your business logic server side, send regular HTML to the client, and you just have a little bit of Js on the frontend that knows how to patch in chunks of HTML in the DOM as needed. Unless you have a highly interactive frontend, this is a much better approach than making a frontend with something like React and adding all the complexity that goes with it.
You really should be doing your IO async. Do you specifically mean callback hell?
No I meant having to do async as opposed to having threads like you would in Java for example. In vast majority of cases a thread pool will work just fine, and it makes your code far simpler. Typically, Java web servers will have a single thread that receives the request and then dispatches it to the pool of workers. The JVM is then responsible for doing the scheduling between the threads and ensuring each one gets to do work. You can do async too, but I've found threads scale to huge loads in practice.
await
and async
Over what?
Death by wasps
Browsers love it!
Practically anything you write will execute without all that scope and well formed statements nonsense.
Mind you, number 2 is also its biggest flaw as well, but…
God people it's getting old
Bro, I'd prefer C# or go for the http sever
Web assembly!!!1
It's* not
Which is a blessing for Java.
.. ah right, it runs on any browser. Lame
It runs in browsers. It… isn’t poop? I don’t know. I’m all out of ideas.
It… isn’t poop?
Well, there's a link that's staying blue.
hmm, let's see.
It's not java.
It's also not a scripting language.
also to the repeat grammar nazi in the comments here, hi, "its"
It’s not a scripting language?
Depends on how you define "scripting language".
Older techs remember when it was only browser-based and they thought of, and perhaps still think of, "scripting languages" as something that would run from some command-line or another. Starting a GUI browser to run a mere script was a ridiculous concept. (There was also that JavaScript had no filesystem access. At least initially. And then it became a gaping security hole, but I digress.)
Today, there exist command-line accessible versions of JavaScript but even there (I figure) most people wince and choose anything else instead. Maybe even Perl.
But another definition of "scripting language" is "(any) interpreted programming language" and where it runs is unimportant.
From that perspective, sure, JavaScript qualifies. And so does QBASIC.
It’s also not a scripting language.
It definitely is a scripting language.
hello-world.js
:
javascript
#!/usr/bin/env node console.log("Hello world");
Your favorite command line tool:
bash
chmod +x ./hello-world.js ./hello-world.js
You just need to install npm
, eg via apt-get install npm
.
everything is a scripting language if you try hard enough.
You can make minecraft mods
that's java
There'll be a modloader in the next 5 years that will have you load .js scripts as mods
Everyone know JavaSript is a Java, but you don't have to compile, so you script in it.
/s
You'll find an npm package to help you count up to 2.
(I recently learned - maybe here - that the is-even package has over 170k weekly downloads)
What's even wilder is if you look at the code of that package, all it does is include the is-odd package and then return !is-odd. And the is-odd package isn't much better, it does some basic checks on the input and then returns n % 2 === 1.
I thought I was missing something. JS is one of my main languages and I always just write the is-odd function myself since it's like 10 characters. It boggles the mind that is-even has 176k weekly downloads
I’ve always looked at stuff like that as much more along the lines of performance art than anything else.
Oh boy, this actually made me laugh out loud
This must be a "hold my beer" kind of joke and someone wanting to see how far they can take it.