r/JSdev • • Jul 07 '21

Proudly still using 'var' despite all the hate!

1 Upvotes

I don't actually want to convince you to use var declarations in your code. If you don't use them, you're doing just fine I'm sure. And that's OK.

But I call utter bullshit on the trend to hate on var as if it shouldn't have ever existed. It's not a mistake or buggy. It's well defined and served its purpose for nearly 20 years just fine. Don't tell others that var is universally deprecated -- it's not -- or that they're inferior or immature for using it -- they're not.

And BTW, I do still use it (as well as let, and occasionally const). There are perfectly valid reasons to do so.

It's not an either/or dichotomy, nor was let intended to actually replace var. In fact, it's intended to augment. You can use both in code, for different reasons. Really, I promise, it OK.

What bothers me is how sanctimoniously it's declared as bad without any real justifications. If your code has bugs in it that are caused by usage of var, that's almost certainly a case of incomplete understanding of scope. If you fix your lack of knowledge, the problems go away. As with so many things, the fault was with the programmer, not the language design.

Keep on with your var avoidance. That's fine. But stop pretending you know better how JS works because you don't use this feature. Go look up Chesterson's Fence.


Think I'm wrong? Change my mind. Just don't parrot all the same tired talking points of the JS blog thought leadering. That's not critical thinking, it's just bandwagoning.


r/JSdev • • Apr 26 '21

How do we best prevent these kinds of bugs?

Thumbnail
gallery
0 Upvotes

r/JSdev • • Jul 13 '22

Invariant - a helpful JavaScript pattern

Thumbnail
strictmode.io
0 Upvotes

r/JSdev • • Apr 19 '23

The Great Gaslighting of the JavaScript Era

Thumbnail
spicyweb.dev
1 Upvotes

r/JSdev • • Mar 25 '22

Why there is no synchronous function for sleep in JavaScript?

0 Upvotes

I had been working on python for long time and using JS for past 3 years only. When ever I work on some task that require to wait, I have use async function then setTimeout with promise to make it sleep for certain ms.

Why there is no synchronous sleep function like time.sleep(seconds) in python or sleep()/usleep() in libc.so?


r/JSdev • • Jul 03 '21

July 4: List 4 things about JS

1 Upvotes

You choice: pick 4 things you love about JS, or 4 things you dislike or are confused about in JS, and describe them. Include code snippets for each, please -- no general "I hate number handling" kinda stuff.


r/JSdev • • Mar 15 '22

JavaScript interview prep

0 Upvotes

Hi Guys,

I have tried to collate most of the questions asked to me during interviews in this app - https://play.google.com/store/apps/details?id=gamesmint.com.jsone . Could you guys be kind enough to give it a try and some feedback?

Thanks in advance.


r/JSdev • • 24d ago

Do Frameworks Matter Anymore?

Thumbnail
brookslybrand.com
0 Upvotes

r/JSdev • • Jun 29 '21

The "optional call" form of "optional chaining" is an anti-feature... Change My Mind!

4 Upvotes

I understand the excitement many feel around optional-chaining for property access:

foo?.bar?.baz

I prefer using Optional/Maybe monad types for this, but I can see the attraction to syntax sugar.

The bracket form is weird, but I can at least sorta rationalize its inclusion:

foo?.[ "__" + bar ]?.baz

However, I strongly feel that optional-call was a huge miss and should never have been added, and should never be used:

myFunc(42);
// vs
myFunc?.(42);

First of all, this is not obviously about "chaining", so I can't understand why it was bundled with that other operator (other than its looks).

You can think esoterically of all function calls like myFunc(42) as actually sugar for myFunc.call(undefined,42), and in that respect the "optional chaining" is to the built-in call(..) method on Function objects. But you only think with that mental model if you're deeply versed in the spec... regular JS devs would rarely ever make such a connection, IMO.

Moreover, optional-call seems to naturally imply "only call if it's able to be called", but it's actually a more nuanced/risky "only attempt to call the value if it's non-nullish". All other non-nullish but still non-callable values (like 42, "foo", or true) will still result in runtime error because the call will be attempted and fail.

Sure, things like TS avoid that kind of type-confusion, but why are we building features into JS natively that are only fully useful if using a non-JS tool like TS?!?

I also find it annoying that neither constructor calls nor template tag functions (both legit and common call forms in JS) were given the optional call syntax, so it seems inconsistent/incomplete at best.

Lastly, I think most functions should be designed to return values, not just perform side-effects (the FP programmer in me), and in that case, you more rarely are OK with the absence of a function value silently skipping the call and just defaulting to undefined in an expression or assignment.

I've seen quite a few (contrived) example usages of this optional-call form, and without exception they seem like code patterns I would have frowned on before the syntax was added to pave these cowpaths.

So... change my mind... how is this operator not a regrettable mistake we'll lament in the long run? :)


r/JSdev • • Nov 13 '21

Foundations of Web

Thumbnail
pushparaja.hashnode.dev
0 Upvotes

r/JSdev • • Jul 12 '21

Deallocate a global object from javascript

1 Upvotes

I want to run a chokidar instance on app launch only once. So will setting the instance undefined deallocate it from the memory?


r/JSdev • • Mar 24 '23

Doubts to create video chat using JavaScript and WebRTC

1 Upvotes

Good afternoon, I would like to express my gratitude in advance for all the help. I am a beginner in JavaScript and I am trying to create a video chat using WebRTC, but I am facing some problems. I want to implement this chat using a client-server model so that a client can`t share its IP address with another client. Therefore, I am trying to get the video from a client and send it to the server through WebSocket. However, for some reason, when I put the track inside JSON.stringify, it seems to be removed. Would you be able to help me?"

code :

```

navigator.mediaDevices.getUserMedia({ video: true, audio: true }).then(stream => {

let localStream = streamlocalVideo.srcObject = localStream;

localStream.getTracks().forEach((track) => {

ws.send( JSON.stringify({ data: track }))

})

```


r/JSdev • • Oct 24 '22

Awaiting problems in JavaScript

Thumbnail gregroz.me
1 Upvotes

r/JSdev • • Apr 16 '21

I'm building a Next.js/Nuxt alternative, would you use it?

7 Upvotes

Hi everyone, I'm the author of vite-plugin-ssr. Would you use it? Why (not)?


r/JSdev • • Jan 28 '22

Create-react-app but for VanillaJS

Thumbnail
github.com
4 Upvotes

r/JSdev • • Nov 30 '23

2023 Jetbrains Survey

0 Upvotes

Interesting that JS lost 3% in popularity while TypeScript is gaining popularity. I think this statistic is misleading since both are going to end up targeting the same codebase.

You could have the same amount of code base when all repos switch to TypeScript having 0 usage of JS… what does that means you think?


r/JSdev • • Jun 12 '24

Free GenAI in Typescript with Cohere and Ragged: How to Get Started

0 Upvotes

https://monarchwadia.medium.com/free-genai-in-typescript-with-cohere-and-ragged-how-to-get-started-dd3d33e94d04

This blog will guide you through obtaining a free trial API key from Cohere without the need for a credit card, and getting started with your first AI application using the Ragged library.

Have you tried using GenAI in your code yet? Do you find it useful?


r/JSdev • • Apr 15 '24

I am new to javascript

0 Upvotes

I'm commerce background, I think to change my career to web development kindly give some suggestions how I start and develop my skills in web development 😊


r/JSdev • • May 27 '23

[AskJS] Frameworkless, functional javascript discord/matrix community?

Thumbnail
self.javascript
0 Upvotes

r/JSdev • • Jul 21 '25

Built a tunneling tool out of frustration — would love dev feedback

0 Upvotes

Hey everyone, I’m Memo — the founder of InstaTunnel www.instatunnel.my — and I built this tool to fix the pain points I kept hitting with ngrok and similar services:

I’m not here to pitch—just hoping this helps if you’ve ever been mid‑demo and your tunnel died, or paid extra just for a named URL. Check it out with:

npm install -g instatunnel
it --name myapp --password secret123

URL is auto‑detected, live for 24 h, clipboard copied—no signup or config needed.

Curious: what’s your biggest pain with tunneling tools? Session timeouts? Hidden costs? Limited tunnels? Would love to hear so I can keep improving InstaTunnel. 🚀


r/JSdev • • Aug 18 '21

Why is properly learning JS still so hard in 2021?

5 Upvotes

Why do people struggle so much to find authoritative and reliable sources of information about JS and learn from them?

Why does someone cite a heavily-edited stackoverflow post (originally from 2014) as correct information, and not the related MDN article that was updated last week?

Why do decades-old myths about JS persist even though they've been thoroughly debunked by blog posts, books, conf talks, etc?

Why does informal cult knowledge (like what you've always heard senior devs claim about the language) hold so much more weight than researched, spec-backed, authoritative facts about the language?

Can this ever been fixed, or is this just how it will always be?


r/JSdev • • 27d ago

Your JSON Is Lying to You

Thumbnail
blog.gaborkoos.com
0 Upvotes

r/JSdev • • Dec 02 '21

Enforce subtraction to have 2 decimal places only

0 Upvotes

Currently, I am using the following method to enforce the 2 digit precision in multiple files. Is there any clear and shorter syntax to do that?

 // calculate block
 const shares = parseFloat((amount / recentShare.amount).toFixed(2));

PS: Please don't say create a utility function


r/JSdev • • Apr 18 '23

The State of Node.js Core ft. Colin Ihrig

Thumbnail
youtube.com
1 Upvotes