Lanackse-Kanvae
No mention for the fact that JS is dynamically typed so that your variables could be pretty much any type and switch at the drop of a hat?
It's not really relevant.
There are problems with its weak typing: Like how + works with objects, arrays, strings, and numbers (not
that it works, but
how it does so.) But dynamic typing simply isn't an issue, I've come to realize.
Lanackse-Kanvae
Most people are used to statically typed languages like Java and C (at least I'm pretty sure C is like that) and that difference can confuse people.
And most people prefer static typing. Which is reasonable. But static typing isn't necessary to make a well-written, stable, reliable, and large program.
However, I've found that
strong typing is necessary for good programs. JavaScript has some strongly-typed tools to keep dynamic typing on a leash - you just have to use them.
Lanackse-Kanvae
An example of this is when taking 2 inputs from dialogue boxes and want to subtract one from the other.
Java would automatically type the input as a String so if you wanted to do some maths with the inputs, you'd have to put it through a parseInt command.
JS wouldn't give two shits and just do the maths.
Which, I agree, is bad. But this isn't because JS is dynamically typed. It's because JS is
weakly typed.
Static typing means that the language requires you to specify - or that it deduces - the type of a variable, and the type of that variable cannot change at runtime.
Dynamic typing means that the language does not bind type information with the variable, and allows the variable to hold different data types at runtime.
Strong typing means that conversions from one type to another are not automatic.
Weak typing means that conversions are implicit and automatic.
For example:
C is statically typed, but weak. You must declare a variable to be an int, but whatever you try to assign to that variable, the language will do its best to make an int out of it.
C++ (well, C++11 specifically) is statically typed and strong. When you declare a variable, it must have a specified type; in a few cases, it can deduce the types of variables or functions, etc. But when you assign to that variable, C++11 requires there to be a valid conversion for weak types, or that you specify a conversion for strong types, and it gives you the tools to make types as strong or weak as you like.
Java is statically typed and strong. It requires types are specified, but no conversions between types are available.
PHP is dynamically typed and extremely weak: It doesn't care what you give it, it'll try to make a string out of it at some point, to hell with logic.
JavaScript is dynamically typed and somewhat weak: It keeps track of the types you use, and makes conversions only when you use math operators. It has some very
wat moments.
It's okay to be dynamic, so long as it's not too weak.