the hardest exam question
the hardest exam question
the hardest exam question
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.
Is-even continues to be the best joke in the industry
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.
Array(16).join("wat" - 1) + " Batman!";
JavaScript: :wide eyed and smiling: Sure why not! You're the boss!
Python: Sighing and downing half a bottle of Advil: Sure. Why not, you're the boss.
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)
The scripting language formerly known as Java.
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.
It's not Malboge.
It's* not
If you are understood buy you're audience, you have spoken correctly. Correcting someone's grammer is pointless
node_modules size of a Linux distro
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.
To be fair, this is actually reasonable. But it does look stupid on the face of it.
IEEE-754
When my console throws a NaN I kinda think of it as an Halloween kid receiving a fruit instead of a candy. They won’t say “That’s a fruit”. They’ll say “That’s not a treat”.
I’m personally pissed more often by a falsy 0.
Did you know that early analog computers would literally explode when asked to divide by 0?
Now computers just say “Hey stupid, that shit is not even a Number in a mathematical sense, but sure I’ll add one to it.” instead of “Why would you kill me like this?”
You can’t really define Infinity as a number, yet it is part of their world.
So typeof NaN === ‘number’ totally makes sense in that regard.
If you ever worked with arrays of dates, don’t judge NaN too harshly.
Easiest? More like... The only way.
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.
Standing on the shoulder of dwarves hiding deep underground
It leads to typescript
You get surprises 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.
If isWeekend doesn't exist, then the weekend doesn't exist, so it's naturally false.
That's why JavaScript gets pushed so hard - it's part of the capitalist agenda to keep us working 7 days a week
That's fair. Typescript has to cook with the existing js ecosystem.
Weren't you getting runtime errors for the function not being found?
You get suprises from npm
await
and async
PHP is actually quite footgun free these days.
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.
I moved from primarily ASP.Net Core backends, which is a hell of a great backend framework btw, to NestJS. Not my choice. I do what the people who sign my paychecks ask for.
I cannot begin to fathom why anyone would willingly choose JavaScript for backend. TypeScript helps a lot but there are still so many drawbacks and poor design decisions that make the developer experience incredibly frustrating. Features that are standard in ASP.Net Core, Django, or other common backend frameworks just don't exist.
Also, don't get me started on GraphQL. Sure, it has performance advantages for websites of a certain size and scale. But 99% of the websites out there don't have the challenges that Facebook has. The added complexity and development cost over REST is just not worth it.
Yeah, gql in particular is a problem looking for a solution in most cases. It makes sense for facebook because they have people building frontend apps for their marketplace, and those apps need all kinds of weird combinations of data. However, this isn't the situation for most apps where you have a fairly well defined set of calls you're doing.
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.
No one cares about graceful degradation anymore. But you can sell management on SEO. Page performance is a key aspect of search engine rankings and server-side rendered pages will almost always have a much faster initial load than client-side rendered.
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.
It has a cup of coffee as logo
That’s Java, not Javascript. Java is to javascript as ham is to hamster.
Or butter to butterfly
I want to create a political party in India. I need you as a candidate for next elections.
Which is a blessing for Java.
It's* not
It is
A lot of people are familiar with it and........um....hackers like it being in use?
Write down any NaN advantages of JavaScript
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.
It runs on mobile also. Hell it runs everywhere nowadays
3 billion devices worldwide?
Half marks
God people it's getting old
How many people are out here raw dogging JS without strict TS or even unit tests
They're not I'm sure, they just wanna removed about a language without caring about why it is how it is.
I use JS if i'm doing something on my own
TS if i have to work with other people
Bro, I'd prefer C# or go for the http sever
Web assembly!!!1
Over what?
Death by wasps
Can I please pick the wasps?
We have forced it, quite hamfistedly, to do anything. The organic hell-evolution of web browsers turned them into do-anything sandboxed mini-OS. It meant whatever hellish code you used to write your corporate mandated web app could now become a perfectly bloated standalone application. And the demonic language that would enable it was called Javascript. It does the backend and it does the frontend. You could consider those advantages over other devices, like toasters and those handheld electronic games from the 80s.
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…
.. ah right, it runs on any browser. Lame
You can make minecraft mods
that's java
Everyone know JavaSript is a Java, but you don't have to compile, so you script in it.
/s
There'll be a modloader in the next 5 years that will have you load .js scripts as mods
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.
bash would be a scripting language, though to be fair, i also consider bash to be pseudo code as well.
If JS is a scripting language, than any other language is a scripting language. And technically, every language can be used to script, so therefore, is a scripting language. i'm referring to the aspect of a scripting language being generally constricted.
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.
Damn this is hard. I keep java script disabled by default so its hard to say anything good. I begrudgingly have to whitelist websites i need that cant run without it.
I feel like that's more because you don't want websites you visit running code than because you dislike this particular programming language
Thats true. It is more to do with code execution than the language itself.
!!isAdvantage
JIT compilation
You can make your speakers go BRRRRRRRRR via Home Assistant with it
Elaborate?
deploy targets, typescript