0% found this document useful (0 votes)
3 views

TypesScript interview

Uploaded by

Name Your
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

TypesScript interview

Uploaded by

Name Your
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Hello. My name is Tinh. I’m 21 years old.

I graduated from Sai Gon Technology


University where I majored in Information Technology. I am a very motivated person and
a fast learner. I enjoy taking part in group activities and can also manage my schedule
well.
 I was introduced to it by an acquaintance in the human resource team
 I don’t know that one, because I never worked with that and I have no idea
 Thank you, thank you for having me, it was really nice to talking to you and
talking about the typescript, I think the interview gave me a lot of things
 It's mostly a matter of add adding more quality to your code and shooting less
bugs into productions and also developing with more speed i would say
1. What is TypesScript?
TypeScript is a typed superset of JavaScript that adds optional static typing, classes,
interfaces, and other features to the language. You will need a compiler to compile and
generate the code in the JavaScript file. Basically, TypeScript is the ES6 version of
JavaScript with some additional features
2. What are the Components of TypeScript?
There are three different types of components in TypeScript which includes:
 Language − It comprises of the syntax, keywords, and type annotations.
 The TypeScript Compiler − This compiler (tsc) converts the instructions
written in TypeScript to its JavaScript equivalent.
 The TypeScript Language Service − The Language Service exposes an
additional layer around the core compiler pipeline, editor-like applications. The
language service supports the common set of typical editor operations.
3. List out the built-in data types in TypeScript.
In TypeScript, the built-in data types are also known as primitive data types and the list
include:
 Number: This represents number type values. The numbers are stored as floating-
point values in TypeScript.
 String: A string represents a sequence of characters stored as Unicode UTF-16
code.
 Boolean: This represents a logical value. When we use the Boolean type, we get
the output only in true or false.
 Null: Null represents a variable whose value is undefined. It is not possible to
directly reference the null type value itself.
 Undefined: The Undefined type denotes all uninitialized variables.
 Void: A void is the return type of the functions that do not return any type of
value.
4. Why do we need TypeScript?
 Using new features of ECMAScript: TypeScript supports new ECMAScript
standards and transpile them to ECMAScript targets of your choice. So, you can use
features of ES2015 and beyond.

 Static Typing: JavaScript is dynamically typed and does not know what type a
variable is until it is actually instantiated at run-time. TypeScript adds type support to
JavaScript.

 Type Inference: TypeScript makes typing a bit easier and a lot less explicit by the
usage of type inference. Even if you don’t explicitly type the types, they are still there to
save you from doing something which otherwise would result in a run-time error.
 Better IDE Support: The development experience with TypeScript is a great
improvement over JavaScript. There is a wide range of IDEs that have excellent support
for TypeScript, like Visual Studio & VS code, Atom, Sublime, and IntelliJ/WebStorm.
5. Mention some of the features of TypeScript
 Cross-Platform: The TypeScript compiler can be installed on any Operating System
such as Windows, MacOS, and Linux.

 Object-Oriented Language: TypeScript provides features like Classes, Interfaces,


and Modules. Thus, it can write object-oriented code for client-side as well as
server-side development.

 Static Type-Checking: TypeScript uses static typing and helps type checking at
compile time. Thus, you can find errors while writing the code without running the
script.

 Optional Static Typing: TypeScript also allows optional static typing in case you are
using the dynamic typing of JavaScript.
6. What are the Benefits of using TypeScript?
 TypeScript is fast, simple, easy to learn and runs on any browser or JavaScript
engine
 It is similar to JavaScript and uses the same syntax and semantics.

 This helps backend developers write front-end code faster.


7. What are the Differences between TypeScript and JavaScript?
TypeScript JavaScript

TypeScript is an Object-
JavaScript is a Scripting language
Oriented language
It has a feature known as Static typing It does not have static typing
TypeScript gives support for modules JavaScript does not support modules
It does not support optional parameter
It supports optional parameter function
function
8. What are Differences between Interfaces and types?
 Interfaces extend syntax is different to types
 Interfaces can be merged - types cannot: Along the same lines, types cannot be
merged, while interfaces can if you declare them multiple times.
 Interfaces cannot extend a primitive: While we can create a type which can be an
alias for a primitive type like string, interface cannot do this.
9. What are Interfaces in TypeScript?
The interface is a structure that defines the contract in your application. It defines the
syntax for classes to follow. It contains only the declaration of the members and it is the
responsibility of the deriving class to define the members. The TypeScript compiler uses
interface for type-checking and checks whether the object has a specific structure or not.
10. What are the access modifiers supported by TypeScript?
TypeScript supports access modifiers public, private and protected which determine the
accessibility of a class member:
 Public – All the members of the class, its child classes, and the instance of the
class can access.
 Protected – All the members of the class and its child classes can access them.
But the instance of the class can not access.
 Private – Only the members of the class can access them.
If an access modifier is not specified it is implicitly public as that matches the convenient
nature of JavaScript.

11. What are modules in TypeScript?


A module is a powerful way of creating a group of related variables, functions, classes,
and interfaces, etc. It can be executed within its own scope, but not in the global scope.
Basically, you cannot access the variables, functions, classes, and interfaces declared in
a module outside the module directly.
A module can be created by using the export keyword and can be used in other
modules by using the import keyword.
12. What is tsconfig.json file?
The tsconfig.json file is a file which is in JSON format. In the tsconfig.json file, you can
specify different options to tell the compiler how to compile the current project. The
presence of a tsconfig.json file in a directory indicates that the directory is the root of a
TypeScript project.
13. What are Generics in TypeScript?
Generics in TypeScript allow you to define a class, interface, or function that can work
with multiple types, rather than a specific type. This allows for greater flexibility and
reusability of code. By using generics, you can write code that is more maintainable,
reusable, and type-safe.
14. What are Rest parameters?
The rest parameter is used to pass zero or more values to a function. It is declared by
prefixing the three-dot characters (‘…’)before the parameter. It allows the functions to
have a variable number of arguments without using the arguments object. It is very
useful where we have an undetermined number of parameters.
15. Explain Enum in TypeScript.
Enums or enumerations are a TypeScipt data type that allows us to define a set of
named constants. Using enums make it easier to document intent, or create a set of
distinct cases. It is a collection of related values that can be numeric or string values.
16. What is method overriding in TypeScript?
If the subclass or the child class has the same method as declared in the parent class, it
is known as method overriding. Basically, it redefines the base class methods in the
derived class or child class.
Rules for Method Overriding:
 The method must have the same name as in the parent class
 It must have the same parameter as in the parent class.
 There must be an IS-A relationship or inheritance.
17. What is namespace in Typescript and how to declare it?
Namespace groups functionalities logically. These maintain the legacy code of typescript
internally. It encapsulates the features and objects that share certain relationships. A
namespace is also known as internal modules. A namespace can also include interfaces,
classes, functions, and variables to support a group of related functionalities.
18. Q29. What is Scope variable?
The scope is a set of objects, variables, and function and the JavaScript can have
a global scope variable and local scope variable.
You can declare a variable in two different scopes such as:
 Local Scope Variable – It is a function object which is used within the
functions
 Global Scope Variable – You can use this window object out of function
and within the functions
19. What is JSX in TypeScript?
JSX is an embeddable XML-like syntax and it is meant to be transformed into a
valid JavaScript. JSX became popular with the React framework. TypeScript
supports embedding, type checking, and compiling JSX directly into JavaScript.
If you want to use JSX in your file, you need to name your file with a .tsx extension
and enable jsx option.
20. What are Ambients in TypeScripts and when to use them?
In TypeScript, "ambient" declarations, often referred to as ambient types or
ambient modules, are a way to define the shape of external entities or objects
that exist outside of your TypeScript code. They are used to provide type
information for external libraries, global variables, and other non-TypeScript code
within your project.
21. Never, any, and unknow
The never type: is typically used to represent values that should never occur. It
often appears in functions that always throw errors or never return.
When: when you want to explicitly indicate that a function will never return
normally (e.g., it will always throw an error or enter an infinite loop). It's a way to
make your code more explicit about exceptional cases.
The any type: is the most flexible type in TypeScript, any doesn’t do any type
checking basically,
It can represent values of any type and allows for dynamic and unsafe behavior
The unknown type: is used to represent values of an unknown type. It is safer
than any because it requires type checking or type assertions to access its
properties or use it in specific ways.
22. What is TypeScript Declare Keyword?
In TypeScript, the declare keyword is used to tell the TypeScript compiler that a
variable, function, class, module, or interface already exists and is defined
somewhere else, typically in a JavaScript file or an external library. This keyword
is primarily used when you're working with external JavaScript libraries or when
you want to describe the shape of objects that are defined outside of your
TypeScript code
23. What is a TypeScript Map file?
TypeScript Map file is a source map file that holds information about our original files.
The .map files are source map files that let tools map between the emitted JavaScript
code and the TypeScript source files that created it. Also, debuggers can consume these
files so we can debug the TypeScript file instead of the JavaScript file
24. What is Type assertions in TypeScript?
Type assertion works like a typecasting in other languages, but it doesn’t perform type
checking or restructuring of data in other languages like C# and Java. The typecasting
comes with runtime support whereas type assertion has no impact on runtime. However,
type assertions are used purely by the compiler and provide hints to the compiler on how
we want our code to be analyzed.

You might also like