Basic Types
Even though JavaScript is a loosely typed language, that does not mean that values do not have types. There are several primitive types that are available to the JavaScript developer. We can get the type of the value using the typeof
operator, available both in JavaScript and TypeScript. Let's inspect some values and see what the results will be:
const value = 1234; console.log(typeof value);
The execution of the preceding code will write the string "number"
to the console. Now, consider another snippet:
const value = "textual value"; console.log(typeof value);
The preceding expression will write the string "string"
to the console. Consider the following snippet:
const value = false; console.log(typeof value);
This will write out "boolean"
to the console.
All of the preceding types are what are called "primitives." They are baked directly into the execution environment, whether that is a browser...