Onboarding Types with Primitive

Primitive types are all the basic supported categories of value. Each type represents a domain of values in which the integrity of the format is enforced. JavaScript has a limited set of primitives that can only be inferred by the assignation of a value to a variable. For example, a value can be a number, a date, a Boolean, a string, and so on. The assignation of a subsequent value of a different model to a singular variable is permitted. The side effect is the mutation of the type, which increases the complexity of any JavaScript program. TypeScript, however, can enforce type immutability, which reduces the risk of a potential wrong value that misleads the proper execution of the application. Also, TypeScript provides support on which operation can be used, depending on which explicit type is attached to a particular value. This chapter illustrates the scoping of a variable, the subtlety between an undefined variable and a null variable, and how to make a variable optional or required. At the end of this chapter, the reader will be in a situation where all the variables will be declared properly, with an accurate type supported by TypeScript. The distinction between a primitive and a non-primitive type will no longer be a conundrum. The use of enum or symbol will be natural and the creation of new types will become a habit any time a new domain object is introduced in your system.

This chapter will cover the following:

  • The difference between var, let, and const
  • How to be strongly typed without specifying the type
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.219.33