0% found this document useful (0 votes)
16 views30 pages

Ilovepdf Merged

Uploaded by

hassanyaseen615
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views30 pages

Ilovepdf Merged

Uploaded by

hassanyaseen615
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Typescript

Exam Preperation
(Part 01)
1. What is TypeScript?

a) A superset of JavaScript

b) A programming language developed by Microsoft

c) A statically typed language that compiles to plain JavaScript

d) All of the above

Answer: d) All of the above

2. Which command is used to install TypeScript globally?

a) npm install typescript

b) npm install -g typescript

c) npm install –global typescript

d) install typescript npm -g

Answer: both (b) & (c)

3. Which file is used to configure TypeScript options for a project?

a) tsconfig.json

b) package.json

c) tscconfig.json

d) typescript.config

Answer: a) tsconfig.json
4. What command compiles TypeScript files in a project?

a) tsc

b) compile

c) ts-compile

d) typescript

Answer: a) tsc

5. How do you install TypeScript locally to a project?

a) npm install -g typescript

b) npm install typescript

c) npm typescript install

d) npm install typescript -g

Answer: b) npm install typescript

6. Which command initializes a new TypeScript project?

a) tsc init

b) tsc --init

c) typescript init

d) typescript --init

Answer: b) tsc –init

7. Which editors provide good support for TypeScript development?

a) Visual Studio Code

b) Sublime Text

c) Atom

d) All of the above


Answer: a) Visual Studio Code

8. What is the file extension for TypeScript files?

a) .ts

b) .js

c) .txt

d) .html

Answer: a) .ts

9. Which command is used to uninstall TypeScript from a project?

a) npm uninstall typescript

b) npm delete typescript

c) npm remove typescript

d) npm uninstall -g typescript

Answer: a) npm uninstall typescript

10. Which npm package manager command is used to initialize a new package.json file?

a) npm init

b) npm create

c) npm new

d) npm generate

Answer: a) npm init

11. How do you check the installed version of TypeScript on your system?

a) npm show typescript version

b) tsc --version

c) tsc -v
d) npm view typescript version

Answer: both (b) & (c)

12. What is the purpose of the cls command?

a) Changes the color scheme of the command prompt

b) Clears the command prompt screen

c) Lists all environment variables

d) Closes the command prompt window

Answer: b) Clears the command prompt screen

13. How do you create a new directory in the command prompt?

a) mkdir directory_name

b) newdir directory_name

c) mk directory_name

d) create directory_name

Answer: a) mkdir directory_name

14. What does the cd command do in the command prompt?

a) Creates a new directory

b) Deletes a file

c) Changes the current directory

d) Copies files

Answer: c) Changes the current directory


15. Which key can you press to autocomplete directory names while typing cd
commands in the command prompt?

a) Tab

b) Enter

c) Shift

d) Backspace

Answer: a) Tab

16. Which command is used to move up one directory level in Unix/Linux systems?

a) cd ..

b) cd..

c) cd ../

d) cd ..

Answer: d) cd ..

17. Which of the following is a Git command used to clone a repository from GitHub to
your local machine?

a) git init

b) git pull

c) git clone

d) git push

Answer: c) git clone

18. What is a README file in a GitHub repository?

a) A file containing instructions for using the code

b) A file containing the code itself


c) A file containing comments about the code

d) A file containing images and screenshots

Answer: a) A file containing instructions for using the code

19. How do you create a new repository on GitHub?

a) Click on the "+" icon and select "New repository"

b) Use the command line interface

c) Write code and push it to GitHub

d) Send an email to GitHub support

Answer: a) Click on the "+" icon and select "New repository"

20. What is a repository in GitHub?

a) A folder on your local computer

b) A collection of files and folders associated with a project

c) A server where code is stored

d) A website hosting platform

Answer: b) A collection of files and folders associated with a project

21. Which of the following is NOT a feature of GitHub?

a) Issue tracking

b) Code reviews

c) Video streaming

d) Pull requests

Answer: c) Video streaming

22. What is GitHub?

a) A version control system


b) A code hosting platform

c) A social network for developers

d) All of the above

Answer: d) All of the above

23. What is the file extension for Javascript files?

a) .ts

b) .js

c) .txt

d) .html

Answer: b) .js

24. In which method do developers use Git commands on GitHub?

a) GitHub Command Line

b) GitHub Desktop

c) GitHub Visual Studio Code

d) GitHub Web Interface

Answer: a) GitHub Command Line

25. Which feature is not present in both JavaScript and TypeScript?

a) Static typing

b) Dynamic typing

c) Interfaces

d) Classes

Answer: a) Static typing


Typescript
Exam Preperation
(Part 02)
26. What keyword is used to declare a variable in TypeScript?

a) var

b) let

c) const

d) Both b) and c)

Answer: d) Both b) and c)

27. Which of the following variable declarations allows reassignment in TypeScript?

a) var

b) let

c) const

d) Both a) and b)

Answer: b) let

28. What is the key difference between var, let, and const in JavaScript/TypeScript?

a) They are all identical and can be used interchangeably.

b) var has block scope, while let and const have function scope.

c) var has function scope, while let and const have block scope.

d) let and const are used for declaring functions, while var is used for variables.

Answer: c) var has function scope, while let and const have block scope.

29. Which of the following is true about TypeScript's type inference for variables?

a) TypeScript cannot infer variable types.


b) TypeScript infers variable types based on the initial value assigned.

c) TypeScript requires explicit type annotations for all variables.

d) TypeScript infers types only for primitive data types.

Answer: b) TypeScript infers variable types based on the initial value assigned.

30. What happens if you declare a variable without initializing it in TypeScript?

a) It throws a compile-time error.

b) It assigns the variable a default value of undefined.

c) It assigns the variable a default value based on its type.

d) It automatically initializes the variable with a random value.

Answer: b) It assigns the variable a default value of undefined.

31. In TypeScript, what is the scope of a variable declared using the var keyword?

a) Global scope

b) Function scope

c) Block scope

d) Module scope

Answer: b) Function scope

32. What is the purpose of declaring a variable as const in TypeScript?

a) To indicate that the variable's value will never change.

b) To indicate that the variable's value will change frequently.

c) To allow the variable to be reassigned multiple times.

d) To specify that the variable should be hoisted.

Answer: a) To indicate that the variable's value will never change.


33 . Which TypeScript feature allows you to enforce stricter variable typing to catch
common errors during development?

a) Type assertions

b) Type inference

c) Type narrowing

d) Type annotations

Answer: d) Type annotations

34. What happens if you try to redeclare a variable using let or const in the same scope
in JavaScript/TypeScript?

a) It throws a syntax error.

b) It ignores the redeclaration and continues executing the code.

c) It automatically converts the variable to a global variable.

d) It updates the value of the variable without any error.

Answer: a) It throws a syntax error.

35. Which of the following statements is true regarding let and const in
JavaScript/TypeScript?

a) Both let and const can be reassigned.

b) let can be reassigned, but const cannot.

c) const can be reassigned, but let cannot.

d) Neither let nor const can be reassigned.

Answer: b) let can be reassigned, but const cannot.

36. Which of the following characters is commonly allowed in variable names in


Typescript?

a) $
b) @

c) #

d) &

Answer: a) $

37. What is the rule regarding starting variable names in Typescript?

a) They must start with a letter.

b) They can start with a letter or a digit.

c) They must start with a special character.

d) They cannot start with a digit.

Answer: a) They must start with a letter.

38. Which of the following is a valid variable name inTypescript?

a) my-variable

b) 1stVariable

c) var#

d) _myVariable

Answer: d) _myVariable

39. In Typescript, which of the following is a common convention for naming variables
with multiple words?

a) Using hyphens between words (e.g., my-variable)

b) Using underscores between words (e.g., my_variable)

c) Using spaces between words (e.g., my variable)

d) Both b) and c)

Answer: b) Using underscores between words (e.g., my_variable)


40. Which of the following variable names is considered to be more readable according
to common coding conventions?

a) numofstudents

b) numOfStudents

c) num_of_students

d) NumOfStudents

Answer: b) numOfStudents

41. Which operator is commonly used for string concatenation in Typescript?

a) +

b) -

c) *

d) /

Answer: a) +

42. In Typescript, what is the result of the following expression: "Hello" + " " +
"World"?

a) HelloWorld

b) Hello World

c) “HelloWorld”

d) SyntaxError

Answer: b) Hello World

43.In Typescript, which symbol is commonly used to terminate a statement?

a) .

b) :
c) ;

d) ,

Answer: c) ;

44. Which of the following is the correct syntax for declaring a variable in Typescript?

a) var myVar = 10;

b) myVar = 10;

c) int myVar = 10;

d) let myVar = 10;

Answer: d) let myVar = 10;

45. What are template literals in TypeScript primarily used for?

a) Declaring variables with constant values.

b) Concatenating strings.

c) Defining multi-line strings.

d) Declaring object literals.

Answer: c) Defining multi-line strings.

46. In TypeScript, what syntax is used to create template literals?

a) Single quotes (' ')

b) Double quotes (" ")

c) Backticks (` `)

d) Square brackets ([ ])

Answer: c) Backticks (` `)

47. Which of the following expressions correctly uses template literals in TypeScript?

a) `Hello, ${name}!`
b) "Hello, ${name}!"

c) 'Hello, ${name}!'

d) [Hello, ${name}!]

Answer: a) `Hello, ${name}!`

48. What advantage do template literals offer over traditional string concatenation in
TypeScript?

a) They provide a simpler syntax.

b) They allow for the interpolation of variables directly into the string.

c) They enforce strict typing of string values.

d) They offer better performance in runtime.

Answer: b) They allow for the interpolation of variables directly into the string.

49. What is the purpose of data types in TypeScript?

a) To restrict the values that a variable can hold.

b) To specify the size of a variable in memory.

c) To define the operations that can be performed on a variable.

d) To specify the order of execution of statements.

Answer: a) To restrict the values that a variable can hold.

50. Which of the following is not a built-in data type in TypeScript?

a) number

b) boolean

c) array

d) string

Answer: c) array
51. What is the data type of the following variable declaration in TypeScript: let age =
25;?

a) string

b) number

c) boolean

d) array

Answer: b) number

52. Which operator is used to perform type assertion in TypeScript?

a) :

b) =

c) <>

d) !

Answer: a) :

53. What is the purpose of type inference in TypeScript?

a) To explicitly specify the data type of a variable.

b) To automatically determine the data type of a variable based on its value.

c) To convert one data type to another data type.

d) To perform type checking at runtime.

Answer: b) To automatically determine the data type of a variable based on its value.

54. What is a type error in programming?

a) An error caused by incorrect syntax.

b) An error that occurs during runtime.

c) An error caused by using an incorrect data type.


d) An error caused by infinite loops.

Answer: c) An error caused by using an incorrect data type.

55. In statically typed languages like TypeScript, when are type errors typically
detected?

a) During compilation.

b) During runtime.

c) After the program has finished executing.

d) Type errors are not detected in statically typed languages.

Answer: a) During compilation.

56. What is the purpose of comments in TypeScript?

a) To execute code.

b) To document code and improve readability.

c) To declare variables.

d) To define functions.

Answer: b) To document code and improve readability.

57. Which symbol is used to start a single-line comment in TypeScript?

a) //

b) #

c) ;

d) /*

Answer: a) //

58. How do you write a multi-line comment in TypeScript?

a) /* This is a multi-line comment /


b) // This is a multi-line comment //

c) /* This is a multi-line comment */

d) // This is a multi-line comment

Answer: c) /* This is a multi-line comment */

59. Which of the following statements about comments in TypeScript is true?

a) Comments are executed by the compiler.

b) Comments are ignored by the compiler.

c) Comments are used to declare variables.

d) Comments are only used for debugging purposes.

Answer: b) Comments are ignored by the compiler.

60. What are operators used for in TypeScript?

a) To declare variables.

b) To perform arithmetic, logical, and other operations on variables and values.

c) To define functions.

d) To document code.

Answer: b) To perform arithmetic, logical, and other operations on variables and


values.

61. Which of the following is an arithmetic operator in TypeScript?

a) &&

b) ||

c) +

d) !

Answer: c) +
62. What does the === operator do in TypeScript?

a) It performs strict equality comparison.

b) It performs logical AND operation.

c) It performs addition.

d) It performs assignment.

Answer: a) It performs strict equality comparison.

63. What does the !== operator do in TypeScript?

a) It performs strict inequality comparison.

b) It performs logical OR operation.

c) It performs subtraction.

d) It performs assignment.

Answer: a) It performs strict inequality comparison.

64. What are logical operators used for in TypeScript?

a) To perform arithmetic operations.

b) To compare values.

c) To combine or manipulate boolean values.

d) To declare variables.

Answer: c) To combine or manipulate boolean values.

65. Which of the following is a logical operator in TypeScript?

a) +

b) &&

c) +

d) *
Answer: b) &&

66. What is the result of the logical AND (&&) operator when both operands are true?

a) true

b) false

c) null

d) undefined

Answer: a) true

67. What is the result of the logical OR (||) operator when one operand is true and the
other is false?

a) true

b) false

c) null

d) undefined

Answer: a) true

68. Which of the following is an example of a logical operator in TypeScript?

a) +

b) +=

c) ||

d) /

Answer: c) ||

69. What is the purpose of the "if" statement in programming?

a) To execute a block of code only if a specified condition is true.

b) To execute a block of code regardless of any condition.


c) To loop through a block of code until a condition becomes false.

d) To define a function.

Answer: a) To execute a block of code only if a specified condition is true.

70. When is the "else" statement used in conjunction with the "if" statement?

a) To execute a block of code only if the specified condition is false.

b) To execute a block of code regardless of any condition.

c) To loop through a block of code until a condition becomes false.

d) To define a function.

Answer: a) To execute a block of code only if the specified condition is false.

71. What is the purpose of the "else if" statement in programming?

a) To execute a block of code only if a specified condition is true, and to execute another
block of code if that condition is false.

b) To execute a block of code only if a specified condition is true.

c) To execute a block of code only if the preceding "if" condition is false and a new condition
is true.

d) To define a function.

Answer: c) To execute a block of code only if the preceding "if" condition is false and a
new condition is true.

72. What is the purpose of the tsc -w command in TypeScript?

a) To transpile TypeScript files into JavaScript files.

b) To watch for changes in TypeScript files and automatically recompile them.

c) To generate TypeScript documentation.

d) To run TypeScript files in watch mode.

Answer: b) To watch for changes in TypeScript files and automatically recompile them.
Typescript
Exam Preperation
(Part 03)
73. What is package.json used for in a Node.js project?

a) To store metadata about the project

b) To define project dependencies

c) To configure project settings

d) All of the above

Answer: d) All of the above

74. Which command is used to install dependencies listed in package.json?

a) npm install

b) npm add

c) npm get

d) npm require

Answer: a) npm install

75. What is the purpose of the devDependencies field in package.json?

a) To specify dependencies required only for development purposes

b) To specify dependencies required only for production purposes

c) To specify dependencies required for both development and production

d) devDependencies is not a valid field in package.json

Answer: a) To specify dependencies required only for development purposes

76. What is the purpose of tsconfig.json in a TypeScript project?

a) To configure TypeScript compiler options


b) To list project dependencies

c) To define project scripts

d) To specify project metadata

Answer: a) To configure TypeScript compiler options

77. What is the purpose of a .gitignore file in a Git repository?

a) To specify which files and directories should be tracked by Git

b) To specify which files and directories should be ignored by Git

c) To define commit messages that Git should ignore

d) To specify which branches should be ignored by Git

Answer: b) To specify which files and directories should be ignored by Git

78. How can you ignore a specific file named example.txt in a .gitignore file?

a) example.txt

b) /example.txt

c) *.txt

d) !example.txt

Answer: a) example.txt

79. What does npm stand for?

a) Node Project Manager

b) Node Package Manager

c) Node Programming Module

d) Node Package Module

Answer: b) Node Package Manager

80. What is the purpose of npm in a Node.js project?


a) To manage project dependencies

b) To run JavaScript code

c) To create web servers

d) To test code

Answer: a) To manage project dependencies

81. What command is used to uninstall a package installed via npm?

a) npm delete <package-name>

b) npm remove <package-name>

c) npm uninstall <package-name>

d) npm purge <package-name>

Answer: c) npm uninstall <package-name>

81. What is the purpose of package-lock.json in npm?

a) To list all installed packages

b) To lock down the version of installed packages

c) To define project scripts

d) To specify project metadata

Answer: b) To lock down the version of installed packages

82. Which prompt type in Inquirer.js presents a list of options for the user to choose
from?

a) Input

b) Confirm

c) List

d) Checkbox
Answer: c) List

83. Which method of Inquirer.js is used to start the prompt interface and receive user
input?

a) start()

b) prompt()

c) init()

d) run()

Answer: b) prompt()

84. How can you install Inquirer.js in your project using npm?

a) npm add inquirer

b) npm install inquirer

c) npm require inquirer

d) npm fetch inquirer

Answer: b) npm install inquirer

85. Which of the following is not a type of prompt supported by Inquirer.js?

a) Input

b) Confirm

c) Array

d) List

Answer: c) Array

86. What is Inquirer.js used for in JavaScript development?

a) As a testing framework

b) To create user interfaces in the terminal


c) To manipulate arrays and objects

d) To manage asynchronous operations

Answer: b) To create user interfaces in the terminal

87. What is Chalk used for in JavaScript development?

a) To create user interfaces in the terminal

b) To format and colorize text output in the terminal

c) To manipulate arrays and objects

d) To manage asynchronous operations

Answer: b) To format and colorize text output in the terminal

88 .Which npm package provides the functionality of styling and coloring text output in
the terminal?

a) Chalk.js

b) TerminalStyler.js

c) Colorize.js

d) StyleMaster.js

Answer: a) Chalk.js

89. How can you install Chalk in your project using npm?

a) npm add chalk

b) npm install chalk

c) npm require chalk

d) npm fetch chalk

Answer: b) npm install chalk

90. Which method of Chalk is used to apply a specific color to text?


a) color()

b) applyColor()

c) setColor()

d) chalk()

Answer: d) chalk()

91. Which of the following is not a style supported by Chalk?

a) Bold

b) Italic

c) Strikethrough

d) Underline

Answer: b) Italic

92. Which tool is designed for users who prefer a visual interface for tasks like
committing changes, creating branches, and resolving merge conflicts?

a) GitHub CLI

b) GitHub Desktop

Answer: b) GitHub Desktop

93. Which of the following describes the syntax for defining an object type in
TypeScript using an interface?

a) interface Person {}

b) type Person = {}

c) class Person {}

d) object Person {}

Answer: a) interface Person {}


94. What happens if you try to directly run a TypeScript file using node without
compiling it first?

a) It will throw a syntax error

b) It will run the TypeScript code directly

c) It will transpile the TypeScript code on-the-fly and then run it

d) It will prompt an error indicating that it's not a valid JavaScript file

Answer: a) It will throw a syntax error

95. Which of the following commands will transpile a TypeScript file and then execute
the resulting JavaScript file?

a) node index.ts

b) tsc index.js && node index.js

c) tsc && node index.ts

d) node index.js && tsc index.js

Answer: b) tsc index.js && node index.js

96. Which of the following is true about TypeScript?

a) It is executed directly in browsers

b) It needs to be compiled into JavaScript before execution

c) It can only be used for server-side programming

d) It is not suitable for object-oriented programming

Answer: b) It needs to be compiled into JavaScript before execution

97. TypeScript provides support for which of the following features that JavaScript
lacks?

a) Static typing

b) Dynamic typing
c) Prototypal inheritance

d) Function overloading

Answer: a) Static typing

98. What is the purpose of the null and undefined types in TypeScript?

a) To represent non-nullable values

b) To represent nullable values

c) To represent numeric values

d) To represent boolean values

Answer: b) To represent nullable values

99. In most programming languages, which symbol is commonly used as the assignment
operator?

a) =

b) ==

c) ===

d) :=

Answer: a) =

100. What is the purpose of the assignment operator in programming?

a) To compare two values

b) To declare variables

c) To assign a value to a variable

d) To perform mathematical operations

Answer: c) To assign a value to a variable


Typescript
Select the correct answer to following multiple choice questions.

1) What is extension for typescript file?


a)abc.js b) abc.ts c) abc.tsc d)none of the
above

2) Which of the following is valid command to compile typescript file?


a) ts abc.ts b) tsc abc.ts c) tsc abc d)none of the
above

3) TypeScript is alibrary which is backed primarily by


a)Google b)Microsoft c)Facebook d)IBM

4) TypeScript compile down to


a)C++ b)Java c)Javascript d)Html

5) Class keywork is:


a)feature of b)feature of c)both a and b d)none of the
javascript typescript above

6) Which of the following is not true about typescript?


a) It supports b)It supports c)It supports d)none of the
inheritance abstract classes. interfaces. above

7) Which of the following is correct way of inheriting in typescript?


a)class B:A{} b)class B inherits c)class B extends d)none of the
A{} A{} above

8) What is role of constructor keyword?


a) No such b)It is used to call c)It is used to d)none of the
keyword exist in constructor of an define constructor above
typescript instance. for class

9) Can we use old plain javascript in typescript?


a)Yes b)No c)Don’t know d)none of the
above

10) Which keyword is used to define class in typescript?


a)Class b)Function c)Prototype d)Closure

11) How to define method of class in typescript?


a)function b) func myFunc() {} c)myFunc() {} d)none of the
myFunc() {} above

12) Typescript support all object oriented principle


a)True b)False c)Don’t know d)none of the
above
13) Typescript provides type checking at
a)run time b)compile time c)load time d)none of the
above

14) Typescript complier use _________ to check type when type is not given
a)type erasure b)type inference c)type annotations d)none of the
above

15) Typescript is ________ of javascript


a)subset b)superset c)both of above d)none of the
above

You might also like