TypeScript is object oriented JavaScript. TypeScript supports object-oriented programming features like classes, interfaces, etc. A class in terms of OOP is a blueprint for creating objects. A class encapsulates data for the object. Typescript gives built in support for this concept called class. JavaScript ES5 or earlier didn’t support classes. Typescript gets this feature from ES6.
পৃষ্ঠাসমূহ
Labels
Search Your Article
CS
Pageviews
Showing posts with label TypeScript Tutorial. Show all posts
Showing posts with label TypeScript Tutorial. Show all posts
Thursday, March 16, 2017
Tuesday, March 14, 2017
TypeScript - Overview
JavaScript was introduced as a language for the client side. The
development of Node.js has marked JavaScript as an emerging server-side
technology too. However, as JavaScript code grows, it tends to get
messier, making it difficult to maintain and reuse the code.
TypeScript - Environment Setup
Try it Option Online
We already have set up TypeScript programming online, so that you can execute all the available examples online at the same time when you are doing your theory work. This gives you confidence in what you are reading and to check the result with different options. Feel free to modify any example and execute it online.
TypeScript - Basic Syntax
Syntax defines a set of rules for writing programs. Every language
specification defines its own syntax. A TypeScript program is composed
of −
- Modules
- Functions
- Variables
- Statements and Expressions
- Comments
TypeScript - Types
The Type System represents the different types of values supported by
the language. The Type System checks the validity of the supplied
values, before they are stored or manipulated by the program. This
ensures that the code behaves as expected. The Type System further
allows for richer code hinting and automated documentation too.
TypeScript - Variables
A variable, by definition, is “a named space in the memory” that
stores values. In other words, it acts as a container for values in a
program. TypeScript variables must follow the JavaScript naming rules −
- Variable names can contain alphabets and numeric digits.
- They cannot contain spaces and special characters, except the underscore (_) and the dollar ($) sign.
- Variable names cannot begin with a digit.
TypeScript - Operators
What is an Operator?
An operator defines some function that will be performed on the data. The data on which operators work are called operands. Consider the following expression −7 + 5 = 12
Here, the values 7, 5, and 12 are operands, while + and = are operators.
The major operators in TypeScript can be classified as −
TypeScript - Decision Making
Decision-making structures require that the programmer specifies one
or more conditions to be evaluated or tested by the program, along with a
statement or statements to be executed if the condition is determined
to be true, and optionally, other statements to be executed if the
condition is determined to be false.
TypeScript - Loops
You may encounter situations, when a block of code needs to be
executed several number of times. In general, statements are executed
sequentially: The first statement in a function is executed first,
followed by the second, and so on.
TypeScript - Functions
Functions are the building blocks of readable, maintainable, and
reusable code. A function is a set of statements to perform a specific
task. Functions organize the program into logical blocks of code. Once
defined, functions may be called to access code. This makes the code
reusable. Moreover, functions make it easy to read and maintain the
program’s code.
TypeScript - Numbers
TypeScript like JavaScript supports numeric values as Number objects.
A number object converts numeric literal to an instance of the number
class. The Number class acts as a wrapper and enables manipulation of
numeric literals as they were objects.
TypeScript - Strings
The String object lets you work with a series of characters. It wraps
the string primitive data type with a number of helper methods.
TypeScript - Arrays
The use of variables to store values poses the following limitations −
- Variables are scalar in nature. In other words, a variable declaration can only contain a single at a time. This means that to store n values in a program n variable declarations will be needed. Hence, the use of variables is not feasible when one needs to store a larger collection of values.
TypeScript - Tuples
At times, there might be a need to store a collection of values of varied types. Arrays will not serve this purpose. TypeScript gives us a data type called tuple that helps to achieve such a purpose.
It represents a heterogeneous collection of values. In other words, tuples enable storing multiple fields of different types. Tuples can also be passed as parameters to functions.
It represents a heterogeneous collection of values. In other words, tuples enable storing multiple fields of different types. Tuples can also be passed as parameters to functions.
TypeScript - Union
TypeScript 1.4 gives programs the ability to combine one or two types. Union types are a powerful way to express a value that can be one of the several types. Two or more data types are combined using the pipe symbol (|) to denote a Union Type. In other words, a union type is written as a sequence of types separated by vertical bars.
TypeScript - Interfaces
An interface is a syntactical contract that an entity should conform to. In other words, an interface defines the syntax that any entity must adhere to.
Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the
Interfaces define properties, methods, and events, which are the members of the interface. Interfaces contain only the declaration of the members. It is the responsibility of the
TypeScript - Objects
An object is an instance which contains set of key value pairs. The values can be scalar values or functions or even array of other objects. The syntax is given below −
Syntax
var object_name = {
key1: “value1”, //scalar value
key2: “value”,
key3: function() {
//functions TypeScript - Namespaces
A namespace is a way to logically group related code. This is inbuilt into TypeScript unlike in JavaScript where variables declarations go into a global scope and if multiple JavaScript files are used within same project there will be possibility of overwriting or misconstruing the same variables, which will lead to the “global namespace pollution problem” in JavaScript.
TypeScript - Modules
A module is designed with the idea to organize code written in TypeScript. Modules are broadly divided into −
- Internal Modules
- External Modules
TypeScript - Ambients
Ambient declarations are a way of telling the TypeScript compiler that the actual source code exists elsewhere. When you are consuming a bunch of third party js libraries like jquery/angularjs/nodejs you can’t rewrite it in TypeScript.
Subscribe to:
Posts (Atom)