In the next few years, Microsoft exploded in popularity, eclipsing Netscape. By the early 2000s, Internet Explorer was the main computer browser, which meant that JScript was now the standard for front-end scripting.
- 2015: ECMAScript6 was created to ensure the interoperability of webpages across various browsers. Developers use it for front-end scripting and creating server services and apps via Node.js.
- Dynamic typing
- First-class functions, which means it treats functions like any other variable
- Prototype-based object-orientation
- Application programming interfaces (APIs) for working with dates, standard data structures, text, regular expressions, and the Document Object Model (DOM)
Primitive values are any data that aren't objects. They include:
- Boolean: Boolean values represent values that can only be true or false.
- Null: The Null type only has one value, "null," and represents an unknown or empty value.
- Number: The Number type is a double-precision 64-bit binary format IEEE 754 value that can store almost any number or integer.
- Undefined: This is for variables that haven't been assigned a value.
- BigInt: This numeric primitive can represent integers beyond the Number type's safe integer limit.
- Symbol: This is an immutable and unique primitive value that can be used as the key of an Object. They are also called "atoms" in other programming languages.
What Is TypeScript?
Microsoft released TypeScript in October 2012 after two years of development. Initially, the language did not provide mature integrated development environment (IDE) support apart from Microsoft Visual Studio.
Over the next couple of years, Microsoft continued adding features to TypeScript, including:
- Support for other IDEs and text editors, including Atom, Vim, and Webstorm
- The ability to prevent variables from being assigned null values
- Language additions such as spread expressions and tuples in rest parameters
- Language features such as Variadic Tuple Types and Custom JSX Factories
How Does TypeScript Work?
First, TypeScript is compiled, rather than interpreted. As such, IDEs that perform background incremental compilation can catch TypeScript errors before execution.
- Type inference
- Type annotations
- Compile-time type checking
- Enumerated types
- Enum: Enum can be used to give more friendly names to numeric value sets. For example, you can use Enum to name a set of colors "color."
- Void: The opposite of any, Void is the absence of any type. You will encounter "void" as the return type of functions that don't return a value.
- Tuple: Devs can use Tuple types to express an array with a fixed number of elements with known types that may not be the same.
- Never: This type represents the type of values that never occur. For instance, Never is the return type of an arrow function expression that never returns.
- Type assertions: Sometimes, devs know more about a value than TypeScript does. They can use type assertions to tell the TypeScript compiler that they have already performed the necessary checks.
- Union: Union types are created from two or more other types. An example would be String | Number, which combines String with Number.
let var2 = "Hello";
var2 = 20;
Let's see how this snippet looks in TypeScript:
let var2: string = "Hello";
var2 = 20;
Executing this results in an error. This is because we assigned a number to var2 after declaring it to be a string. TypeScript's strongly typed system doesn't allow you to change variable types.
- Interactive maps
- Dynamic content that change based on user preferences, data, and behavior
TypeScript Use Cases
- Real-time chat applications
- Social media platforms
- Real-time weather apps
- File sharing applications
However, if your project is complex and you have some TypeScript experts, consider picking TypeScript. TypeScript's static typing empowers devs to check type accuracy at build time. It can also spot and fix bugs during compilation, giving devs more time to focus on the build and deployment steps of the software development lifecycle (SDLC).
TypeScript also provides many other functionalities for web and mobile development, including:
- Generics for creating a component that can work across a variety of types
- Namespaces for logically grouping functionalities
- Interfaces that tell the compiler which property names an object can have
- Null checking for setting pointers that don't point to anything as null
- Access modifiers for encapsulating class and member variables
- The ability to make parameters optional