Professional Documents
Culture Documents
Unit 2 Part-1
Unit 2 Part-1
Unit 2 Part-1
SEMESTER – 3
0302302
INTRODUCTION TO ANGULAR
UNIT -2 Introduction to Typescript
●
Introduction to TypeScript
●
Datatypes and Variables
●
Writing and Using Classes
●
Constructor Method
●
"TypeScript is JavaScript for application-scale development.”
●
TypeScript is a strongly typed, object oriented, compiled
language.
●
It was designed by Anders Hejlsberg (designer of C#) at
Microsoft.
●
TypeScript is both a language and a set of tools.
●
TypeScript is a typed superset of JavaScript compiled to
JavaScript.
●
In other words, TypeScript is JavaScript plus some additional
features.
●
TypeScript is an open-source pure object-oriented
programing language.
●
It is a strongly typed superset of JavaScript which
compiles to plain JavaScript.
●
It contains all elements of the JavaScript. It is a language
designed for large-scale JavaScript application
development, which can be executed on any browser, any
Host, and any Operating System.
●
The TypeScript is a language as well as a set of tools.
●
TypeScript supports JavaScript libraries: TypeScript supports each
JavaScript elements. It allows the developers to use existing JavaScript
code with the TypeScript. Here, we can use all of the JavaScript
frameworks, tools, and other libraries easily.
●
JavaScript is TypeScript: It means the code written in JavaScript with
valid .js extension can be converted to TypeScript by changing the
extension from .js to .ts and compiled with other TypeScript files.
●
DOM Manipulation: TypeScript can be used to manipulate the
DOM for adding or removing elements similar to JavaScript.
●
TypeScript is just a JS: TypeScript code is not executed on any
browsers directly. The program written in TypeScript always starts
with JavaScript and ends with JavaScript.
One.ts
Step 1 − Save the file with .ts extension. We shall save the
file as Test.ts. The code editor marks errors in the code, if any,
while you save it.
●
A variable is the storage location, which is used to store
value/information to be referenced and used by programs.
●
These rules are-
– The variable name must be an alphabet or numeric
digits.
– The variable name cannot start with digits.
– The variable name cannot contain spaces and special
character, except the underscore(_) and the dollar($)
sign.
2. Declare its type but no value. In this case, the variable will be set to
undefined.
Eg : var name:string;
●
Identifiers in TypeScript
– Identifiers are names given to elements in a program like variables,
functions etc. The rules for identifiers are −
●
Identifiers can include both, characters and digits. However, the
identifier cannot begin with a digit.
●
Identifiers cannot include special symbols except for underscore (_)
or a dollar sign ($).
●
Identifiers cannot be keywords.
●
They must be unique.
●
Identifiers are case-sensitive.
●
Identifiers cannot contain spaces.
●
keywords
break as any switch
case If else throw
var number string get
Moduel type Instanceof typeof
Public private enum export
finally For while void
null super this new
in return true false
any extends static let
package implements interface function
new try yield const
continue Do catch
●
TypeScript is Case-sensitive
– TypeScript is case-sensitive. This means that
TypeScript differentiates between uppercase and
lowercase characters.
●
Comments in TypeScript
– TypeScript supports the following types of comments −
●
Single-line comments ( // ) − Any text between a //
and the end of a line is treated as a comment
●
Multi-line comments (/* */) − These comments may
span multiple lines.
●
Any Type
– The any data type is the super type of all types in
TypeScript. It denotes a dynamic type. Using the any
type is equivalent to opting out of type checking for a
variable.
●
User-defined Types
– User-defined types include Enumerations (enums),
classes, interfaces, arrays, and tuple.
●
Buit – in Type
●
TypeScript Variable Scope
– The scope of a variable specifies where the variable is
defined. The availability of a variable within a program
is determined by its scope. TypeScript variables can be
of the following scopes −
– Global Scope − Global variables are declared
outside the programming constructs. These
variables can be accessed from anywhere within your
code.
●
TypeScript Variable Scope
– Class Scope − These variables are also called fields.
Fields or class variables are declared within the class
but outside the methods. These variables can be
accessed using the object of the class. Fields can also be
static. Static fields can be accessed using the class name.
●
The major operators in TypeScript can be classified as −
– Arithmetic operators
– Logical operators
– Relational operators
– Bitwise operators
– Assignment operators
– Ternary/conditional operator
– String operator
– Type Operator
●
The major operators in TypeScript can be classified as
−
– Miscellaneous Operators
●
negation operator (-)
●
String Operators: Concatenation operator (+)
●
Conditional Operator (?)
●
typeof operator