wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

JavaScript and TypeScript Quiz

Total questions: 107

Worksheet time: 54mins

Name
Class
Date
1.

What is the purpose of `let` in JavaScript?

a)

It creates a global variable

b)

It creates a block-scoped variable

c)

It creates a constant variable

d)

It creates an undefined variable

2.

How does JavaScript handle asynchronous code?

a)

Using event loops

b)

Using synchronous execution

c)

Using promises only

d)

Using immediate callbacks

3.

What is the difference between `null` and `undefined` in JavaScript?

a)

Both represent no value

b)

`null` is assigned, `undefined` means no assignment

c)

`undefined` is an object, `null` is a number

4.

What is a closure in JavaScript?

a)

A function inside another function that remembers the environment

b)

An immediate function call

c)

A function that modifies its own scope

d)

A class-based function

5.

What is `this` keyword in JavaScript?

a)

Refers to the global object

b)

Refers to the object in the current execution context

c)

Always refers to the DOM element

d)

Refers to the window object in strict mode

6.

How does `bind()` work in JavaScript?

a)

It binds a function to a context object

b)

It creates a copy of a function

c)

It modifies the value of `this`

d)

It permanently changes the prototype of an object

7.

What is the purpose of `Object.assign()`?

a)

To assign values to variables

b)

To merge objects into one

c)

To create a copy of an array

d)

To delete properties from an object

8.

What is the event delegation in JavaScript?

a)

Directly attaching events to child elements

b)

Attaching events to a parent element to capture events on child elements

c)

Blocking event propagation

d)

Handling form submission with callbacks

9.

How does `async` and `await` work in JavaScript?

a)

`async` turns a function into a promise, `await` pauses execution until the promise resolves

b)

`async` forces synchronous behavior, `await` is for handling errors

c)

`await` works only with synchronous functions

d)

`async` returns only errors

10.

What is the difference between `forEach` and `map` in JavaScript?

a)

`forEach` returns a new array, `map` modifies the original

b)

`forEach` modifies the original, `map` returns a new array

c)

`forEach` works on arrays only, `map` works on objects

d)

`forEach` can stop early, `map` cannot

11.

How does prototypal inheritance work in JavaScript?

a)

Objects inherit directly from other objects via prototypes

b)

Classes extend other classes through prototypes

c)

Functions can only inherit through prototypes

d)

Prototypes exist only on arrays and strings

12.

What is hoisting in JavaScript?

a)

Function and variable declarations are moved to the top of their scope

b)

Only variables are moved to the top of their scope

c)

Functions are executed at the end

d)

Objects are declared before variables

13.

What are the benefits of using arrow functions over traditional functions?

a)

Arrow functions are more performant

b)

Arrow functions do not have their own `this` context

c)

Arrow functions have global scope

d)

Arrow functions prevent memory leaks

14.

What is the purpose of the `spread` operator in JavaScript?

a)

To spread out the elements of an array

b)

To combine objects into one

c)

To perform destructuring

d)

To change the scope of a function

15.

What are JavaScript promises?

a)

A way to handle synchronous code

b)

A way to execute a function immediately

c)

A proxy for a value that will be available in the future

d)

A method to bind events

16.

How does `setTimeout` differ from `setInterval`?

a)

`setTimeout` runs code after a delay, `setInterval` runs code repeatedly

b)

`setTimeout` stops after one call, `setInterval` runs until stopped

c)

`setTimeout` modifies scope, `setInterval` forces global execution

d)

`setTimeout` returns a callback, `setInterval` doesn't

17.

What is the `call()` method used for in JavaScript?

a)

To invoke a function with a specific `this` context

b)

To define a new function

c)

To modify object properties

d)

To access an object's prototype chain

18.

How does JavaScript handle errors in promises?

a)

With try-catch blocks

b)

With promise chaining

c)

With `catch()` for rejected promises

d)

By returning undefined for failed promises

19.

What is `strict mode` in JavaScript?

a)

It prevents variable hoisting

b)

It enforces stricter parsing and error handling

c)

It disallows function calls within loops

d)

It modifies event propagation

20.

What is destructuring in JavaScript?

a)

Breaking down complex objects into simpler ones

b)

Copying objects without references

c)

Assigning object properties to variables directly

d)

Removing properties from objects

21.

What are template literals in JavaScript?

a)

String literals that support multi-line strings and expressions

b)

Special functions to handle arrays

c)

Functions that deal with string interpolation

d)

Methods for creating promises

22.

What is the purpose of the `reduce` method in JavaScript?

a)

To sum array values

b)

To return a new array

c)

To accumulate a single value based on array elements

d)

To break an array into chunks

23.

How does JavaScript's event loop work?

a)

It processes events asynchronously using a queue

b)

It blocks execution until events complete

c)

It handles synchronous execution only

d)

It executes events in parallel

24.

What is the purpose of TypeScript's `interface`?

a)

To define the structure of an object

b)

To define a function's signature

c)

To handle class inheritance

d)

To enforce private variables

25.

What is the difference between `interface` and `type` in TypeScript?

a)

`interface` is more flexible than `type`

b)

`type` can represent unions and intersections

c)

`type` is used for methods only

d)

`interface` handles object literals only

26.

What is TypeScript's `any` type?

a)

A type that can hold any value

b)

A type that enforces type checking

c)

A type that disables the compiler

d)

A type for arrays and objects

27.

How does `readonly` work in TypeScript?

a)

It allows variables to be assigned only once

b)

It prevents variables from being mutated

c)

It forces shallow comparison of objects

d)

It handles class inheritance

28.

What is the purpose of TypeScript's `enum`?

a)

To define a set of named constants

b)

To create variables with restricted values

c)

To ensure type safety in functions

d)

To manage state in classes

29.

How does TypeScript handle optional properties?

a)

By using `?` after the property name

b)

By using `null` values

c)

By enforcing default values

d)

By using the `readonly` keyword

30.

What is the difference between `unknown` and `any` in TypeScript?

a)

`unknown` enforces type checking, `any` does not

b)

`unknown` is for functions, `any` is for objects

c)

`unknown` is for errors, `any` is for types

d)

`unknown` disables type safety

31.

How do generics work in TypeScript?

a)

They allow functions and classes to operate on multiple types without specifying them

b)

They enforce strict typing

c)

They create multiple instances of a class

d)

They define constant values for objects

32.

How do you enforce function argument types in TypeScript?

a)

By specifying types in the function signature

b)

By using `any` for all arguments

c)

By using optional parameters

d)

By adding type assertions

33.

What is the `never` type used for in TypeScript?

a)

For functions that never return

b)

For variables that can hold any value

c)

For default type parameters

d)

For methods that have optional arguments

34.

What is the difference between `null` and `undefined` in TypeScript?

a)

`null` must be explicitly assigned, `undefined` means a variable has not been initialized

b)

`null` and `undefined` are equivalent in TypeScript

c)

`undefined` is an object, `null` is a string

35.

What are modules in TypeScript?

a)

Blocks of code to split functionalities into files

b)

Templates for functions

c)

Reserved words for type definitions

d)

Methods to handle async code

36.

How does `type assertion` work in TypeScript?

a)

By overriding the inferred type of a variable

b)

By creating a union of types

c)

By adding an interface to the type

d)

By forcing a specific return type

37.

What is the purpose of `namespace` in TypeScript?

a)

To group logically related code and avoid global scope pollution

b)

To define private methods

c)

To handle errors in classes

d)

To manage memory efficiently

38.

What is the difference between `var` and `let` in JavaScript?

a)

`var` is function-scoped, `let` is block-scoped

b)

`let` allows hoisting, `var` does not

c)

`var` is block-scoped, `let` is function-scoped

d)

`var` creates constants, `let` does not

39.

How does `export` and `import` work in TypeScript?

a)

They allow functions and variables to be shared across files

b)

They handle object destructuring

c)

They manage promises in async functions

d)

They manage object lifecycles

40.

How do decorators work in TypeScript?

a)

They add behavior to classes or methods

b)

They define type assertions

c)

They enforce immutability

d)

They handle object inheritance

41.

What is the purpose of `type guards` in TypeScript?

a)

To check if a value conforms to a specific type

b)

To handle errors in functions

c)

To prevent variable reassignment

d)

To enforce immutability

42.
What are the three main 'simple types' in TypeScript?
a)
Array, Object, Boolean
b)
Boolean, Number, String
c)
Object, String, Number
d)
Object, Array, String
43.
What type of assignment is this variable, `const fullName: string = 'Dylan Israel';`?
a)
Explicit
b)
Implicit
44.
True or False: TypeScript can always correctly infer a variables type.
a)
True
b)
False
45.
You can disable implicit variable type assignment by enabling the compiler option:
a)
noImplicitAny
b)
noAutoType
c)
Implicit = FALSE
d)
autoTypeAssignment = FALSE
46.
TypeScript is a ?
a)
Strongly typed
b)
Object oriented
c)
Compiled language
d)
All of the above
47.
Who developed TypeScript language?
a)
Apple
b)
IBM
c)
Microsoft
d)
Google
48.
You can enable 'undefined' and 'null' types to be accounted for by enabling the compiler property:
a)
noAutoType
b)
noFalseyInits
c)
strictChecksRequired
d)
strictNullChecks
49.
Which of the following are features of typeScript?
a)
TypeScript is portable
b)
TypeScript is just JavaScript
c)
TypeScript supports other JS libraries
d)
All of the above
50.
What is the inherited type for the variable example in 'const example = ['Dylan']'?
a)
any[]
b)
string[]
c)
string
d)
unknown[]
51.
True or False: a Tuple and an Array are the same thing when discussing types
a)
True
b)
False
52.
Which is a successful example of this tuple '[number, string]'?
a)
const ourTuple = [101]
b)
const ourTuple = ['Coding God', 101]
c)
const ourTuple = [101, 101, 'Coding God', 'Coding God']
d)
const ourTuple = [101, 'Coding God']
53.
Type Aliases are mostly used with ______.
a)
Strings
b)
Booleans
c)
Numbers
d)
None of the above
54.
Interfaces are similar to type aliases, but only for object types?
a)
True
b)
False
55.
________ an interface will have the same properties as that interface.
a)
Idolizing
b)
Improving
c)
Extending
d)
Duplicating
56.
What are the two types of enums?
a)
String and Boolean
b)
String and Number
c)
Number and Boolean
d)
Number and Number Array
57.
What is the type of the parameter: 'function ex(param1?: string){}'?
a)
string
b)
string | undefined
c)
string | null
d)
unknown
58.
_____ is a return type for when nothing is returned.
a)
void
b)
any
c)
any[]
d)
unknown
59.
How TypeScript allow you to specify multiple possible types for a single variable or parameter.
a)
Union types
b)
Intersection types
c)
Type aliases
d)
Keyof operator
60.
3 Types of typescript are ?
a)
Object types
b)
Primitive types
c)
Other types
d)
Function types
61.
What are variables in Typescript?
a)
A variable name should contain alphabets and numeric digits
b)
A variable name cannot begin with a digit
c)
It cannot contain spaces and special characters except underscore (_) and dollar ($) sign
d)
All of the above
62.

What does TypeScript add to JavaScript that makes it more robust?

a)

Strongly-typed variables

b)

Dynamic typing

c)

Automatic memory management

d)

Built-in debugging tools

63.

What is the purpose of TypeScript's "Type Declaration"?

a)

To define the types of data a variable can hold

b)

To declare a new variable

c)

To perform type casting

d)

To add comments to the code

64.

Typescript is

a)

interpreted language

b)

compiled language

65.

What does TypeScript add to JavaScript to help catch errors at compile time?

a)

Static typing

b)

Dynamic typing

c)

Runtime checks

d)

Enhanced performance

66.

In TypeScript, which keyword is used to declare a variable?

a)

let

b)

const

c)

var

d)

type

e)

variable

67.

Which of the following is used to indicate the type of a variable in TypeScript?

a)

typeOf

b)

isType

c)

:

d)

#

68.

What tool can you use to transpile TypeScript code into JavaScript code?

a)

TypeScript Compiler (tsc)

b)

JavaScript Transformer (jst)

c)

TypeScript Formatter (tsf)

d)

JavaScript Linter (eslint)

69.

Javascript is a subset of Typescript

a)

True

b)

False

70.

JSON is

a)

Used to store data

b)

Used to transfer Data

c)

File format

d)

Used to maintain the version of packages

e)

Used for Configuration setting

71.

Our project is dependent on some packages (called as dependencies) and these packages are dependent on some other dependencies and those dependencies are further dependent on some other dependencies and so on these are called as

(a)  

72.

What is node module in our project?

a)

store your all packages

b)

all the dependencies are inside the node module

c)

it manage the version of our project

d)

it lock all the packages

e)

None of above

73.

What is the shortest program of javascript?

(a)  

74.

What is an output of this code?
const a = "Quiz 1"

a = "Quiz cancel"

a = "Quiz postponed"

console.log(a)

a)

Quiz 1

b)

Quiz cancel

c)

Quiz postponed

d)

Error

75.

What is an output of this code?
let var1 = "Typescript Cheety"

var1 = "23"

console.log(var1)

a)

Type Number is not assignable to Type string

b)

23

c)

Typescript Cheety

d)

Error

76.

Below code is in Typescript file and is an example of ?
let var1 = "Typescript Cheety"

var1 = "Python Cheety"

console.log(var1)

a)

Type Inferance

b)

Explicit Typing

c)

Dynamic Typing

d)

None of Above

77.

The JSON object is written inside curly braces { }

a)

True

b)

False

78.

JSON object is only used in javascript and typescript language.

a)

True

b)

False

79.

JSON is similar to Javascript object.

a)

True

b)

False

80.

As JSON is similar to javscript object so we can access it using dot notation

a)

True

b)

False

81.

What is an output of this code?

let var1 : string = "Pakistani Developers "

let var2 : string = "are number "

let var3 : string = "1"


console.log(var1 + var2 + var3)

a)

Number is not assignable to type string

b)

Error: Strings cannot be added together

c)

Pakistani Developers are number 1

d)

None of above

82.

What is an output of this code?

let var1 : string = "Welcome to programming"

var1 = 101

console.log(var1)

a)

Welcome to programming

b)

101

c)

Welcome to programming 101

d)

Type number is not assignable to type string

83.

We can reassign value to a variable that initialize with const

a)

True

b)

False

84.

We can reassign value to a variable that initialize with let

a)

True

b)

False

85.

What is an output of this code in typescript file?

let var1;

var1 = "Welcome to typescript class"

var1 = 23

var1 = false

console.log(var1)

a)

Welcome to typescript class

b)

23

c)

false

d)

Error

86.

What typescript compiler infer the datatype in below code

let value = null;

a)

Unknown

b)

void

c)

any

d)

undefined

e)

null

87.

What is an output of below code?

let value : null = 101;

console.log(value)

a)

101

b)

null

c)

undefined

d)

Error

88.

How would you describe Typescript as a programming language?

a)

Strongly Typed

b)

Weakly Typed

c)

Dynamically Typed

d)

Statistically Typed

89.

Which file extension is commonly used for TypeScript files?

a)

.js

b)

.tx

c)

.ts

d)

.tys

90.

TypeScript code is ultimately compiled into which language?

a)

C++

b)

Java

c)

Python

d)

JavaScript

91.

What command correctly represents build/compiling Typescript to JavaScript

a)

build

b)

tsc

c)

node tsc

d)

build tsc

92.

const student = 'Usman';

The implicit type here is a?

a)

Number

b)

String

c)

Boolean

d)

Object

93.

Which of the following correctly define an explicit type?

a)

let a = true

b)

let a: boolean = true

c)

let a = true:bolean

d)

let boolan: a = true

94.

At what time does checks in Typescripts occur?

a)

Run time

b)

Compile time

c)

Code time

d)

Dev Time

95.

Rasheed wants to create an array of only strings, which syntax should he use?

a)

names = [ ]

b)

names: any = [ ]

c)

names: string = [ ]

d)

names: string[] = [ ]

96.

Using this function:

const addNum = (num1: number, num2: number, num4?:number, num3: number = 10) => {}

num3 represents?

a)

Optional parameters

b)

Default parameters

c)

Return type

d)

None of the options

97.

Using this function:

const addNum = (num1: number, num2: number, num4?:number, num3: number = 10) => {}

num4 represents?

a)

Optional parameters

b)

Default parameters

c)

Return type

d)

None of the options

98.

Ella is creating a function to integrate data service providers(mtn, glo, etc). Which of the following concepts can help her define the different providers in her function

a)

Type alias

b)

Switch parameters

c)

Optional parameters

d)

Generics

99.

Which of the following is used to create a union type in TypeScript?

a)

&

b)

|

c)

~

d)

^

100.

What is the purpose of the "unknown" data type in TypeScript?

a)

Represents a variable that can have any type

b)

Represents a function that never returns

c)

Represents an object with an unknown structure

d)

There is no unkonwn

101.

How can you declare a generic type in TypeScript?

a)

Using the "generic" keyword

b)

Using the "type" keyword

c)

Using the "<>" syntax

d)

Using the "any" keyword

102.

A class can implement an interface

a)

True

b)

False

c)

How na??

d)

None of the options

103.

const createPerson = <T>(person: T) => ...

Which of the following is a correct way to use the above function

a)

createPerson('sam')

b)

createPerson(true)

c)

createPerson({

name: 'sam'

})

d)

All of the options

104.

enum Color {

Red,

Green,

Blue,

}

What is the value of blue?

a)

0

b)

1

c)

2

d)

3

105.

let x: [string, number];

What does this represent?

a)

Any Type

b)

Union Type

c)

Tuples

d)

Array Type

106.

Which of the following is not an access modifier

a)

Public

b)

Private

c)

Protected

d)

Readonly

e)

Static

107.

What is the purpose of the "typeof" operator in TypeScript?

a)

To check the type of a variable

b)

To define a new variable

c)

To create an instance of an object

d)

To import external modules