Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Variable name spell-checking in JavaScript

Maybe this is a very lame question but I'm not a JavaScript professional. Please excuse my very basic question. We all do know that JavaScript (node.js) is a dynamically typed language. Moreover, one can simply write:

someObject.attr = 123;

But because of no compile-time checking we can also misspell the attribute name and write:

someObject.misspelledAttr = 123;

and produce a bug.

My question is: What is the most principal and currently used solution for that problem? Writing tests? Some tools? I have no idea if there even could be any "strong" solution.

like image 471
Cartesius00 Avatar asked Jul 02 '26 17:07

Cartesius00


1 Answers

As for tools, there are languages like TypeScript that add compile-time checking. So you get a language that is very close to Javascript with some extra annotations, and it compiles to regular Javascript.

Also, if your text editor does autocompletion based on words that already exist in the project, that goes a long way, too, as far as typos go.

like image 131
Thilo Avatar answered Jul 04 '26 15:07

Thilo