But without knowing the good parts, we won’t be writing code as cleaning as we could.
We can use dynamic types to our advantage. With or without strong typing, we got to test our code thoroughly.
Otherwise, we’re going to run into issues regardless of whether the language has strong typing or not.
Type errors are only one class of errors and we can eliminate that with tests that we have to type anyways.
We can create objects without creating classes.
Simple Testing Ground
Both Node.js and browsers have a REPL where we can test out our code.
Many of those editors even have templates for creating projects with various frameworks out of the box.
We can also include libraries on the fly.
With REPLs and online editors, we can create tests and prototype code without much effort.
In all the editors and REPLs, we can see the results right away.
However, there are some whitespace that are required to separate some tokens like keywords and variables.
For instance, if we have:
const foo = this;
Then the space after the
const is required, but the rest are not.
Comments are good to add to let us clarify our code.
We can write comments with blocks surrounded with
/* */ or start with
2 forward slashes are also used by regex literals, so we probably don’t want to use them.
Instead, we can create comment blocks with
/* */ .
We can’t use reserved words as function names, class names, or variable names.
Floating point numbers and interest are all one type.
This is more convenient than having separate types for different kinds of numbers.
Having one type of number eliminates the type of errors that are caused by different types of numbers.
If a number has an exponential part, then the value of the literal is computed by multiplying the part before the
e by 10 raised to the power after the
For instance, the number 1000 and
1e3 are the same number.
Negative numbers are formed by the
- prefix operator.
NaN is a number value that’s the result of an operation that can’t produce a number.
NaN isn’t equal to any value, including itself.
For instance, if we divide a number by 0, then we get
We can check if something produces
NaN by using the
Number.isNaN method, which checks the value as-is, or the
isNaN function, which does the conversion to number before checking the returned value.
Numbers have various methods that we can use to manipulate them. Also, we can do
Math with the
We can use dynamic typing to our advantage. The ability to create and use object literals is a convenience feature that many programming languages don’t provide.
It also has comments we can use to clarify code.