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

TypeScript

The document contains a series of multiple-choice questions and answers related to JavaScript concepts, including function declarations, event handling, data types, and object manipulation. It also includes practical programming tasks such as finding the largest element in an array and checking for palindromes. The content serves as a quiz or study guide for JavaScript programming knowledge.

Uploaded by

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

TypeScript

The document contains a series of multiple-choice questions and answers related to JavaScript concepts, including function declarations, event handling, data types, and object manipulation. It also includes practical programming tasks such as finding the largest element in an array and checking for palindromes. The content serves as a quiz or study guide for JavaScript programming knowledge.

Uploaded by

saksham.kumar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

TypeScript:

How do you declare a function in JavaScript?

a) function myFunction() { }

b) myFunction = function() { }

c) let myFunction = () => { }

d) All of the above

Answer: d) All of the above

What is the purpose of the "addEventListener" method in JavaScript?

a) To create new HTML elements dynamically

b) To retrieve elements from the DOM using a CSS selector

c) To add event listeners to elements

d) To set attributes for elements

Answer: c) To add event listeners to elements

Which method is used to convert a string to an integer in JavaScript?

a) parse()

b) toInteger()

c) parseInt()

d) convertToInt()

Answer: c) parseInt()

How do you write an "if" statement in JavaScript?

a) if (condition) { }

b) when (condition) { }

c) case (condition) { }

d) condition { }

Answer: a) if (condition) { }

What is the purpose of the "return" statement in a JavaScript function?


a) To end the execution of the function

b) To output a value from the function and end its execution

c) To loop back to the start of the function

d) To skip the current iteration of a loop

Answer: b) To output a value from the function and end its execution

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

a) Both represent empty values, and there is no difference between them.

b) "null" is assigned explicitly by the developer, while "undefined" is assigned by the JavaScript
engine.

c) "null" represents an empty value, while "undefined" indicates the absence of a value or
uninitialized variable.

d) "null" is a reserved keyword and cannot be used in JavaScript, while "undefined" is used to
terminate loops.

Answer: c) "null" represents an empty value, while "undefined" indicates the absence of a value or
uninitialized variable.

What is the purpose of a closure in JavaScript?

a) To define a set of styles for web pages.

b) To encapsulate data and behavior and maintain private variables.

c) To convert a string to an integer.

d) To create new HTML elements dynamically.

Answer: b) To encapsulate data and behavior and maintain private variables.

How do you check if a variable is an array in JavaScript?

a) By using the "isArray" method of the variable.

b) By checking if the variable's type is "array".

c) By using the "Array.isArray()" method.

d) JavaScript does not support arrays; it uses objects instead.

Answer: c) By using the "Array.isArray()" method.

What is the difference between "call" and "apply" in JavaScript?


a) There is no difference; both methods are used interchangeably to invoke functions with
arguments.

b) "call" is used to invoke functions with an array of arguments, while "apply" is used with a single
argument.

c) "call" is used to invoke functions with a single argument, while "apply" is used with an array of
arguments.

d) "call" and "apply" are used to invoke functions on different data types in JavaScript.

Answer: b) "call" is used to invoke functions with an array of arguments, while "apply" is used with a
single argument.

How can you prevent event bubbling in JavaScript?

a) By using event delegation.

b) By setting the "stopPropagation" method on the event object.

c) By using the "preventDefault" method on the event object.

d) Event bubbling cannot be prevented in JavaScript.

Answer: b) By setting the "stopPropagation" method on the event object.

What is the purpose of the "bind" method in JavaScript?

a) To bind event listeners to elements.

b) To merge two or more arrays into a single array.

c) To concatenate strings.

d) To set the value of "this" within a function explicitly.

Answer: d) To set the value of "this" within a function explicitly.

What is a Promise in JavaScript used for?

a) To handle exceptions in asynchronous code.

b) To define the entry point of a JavaScript program.

c) To perform asynchronous operations and handle their results.

d) To create animations and transitions on web pages.

Answer: c) To perform asynchronous operations and handle their results.

How do you clone an object in JavaScript?


a) By using the "clone()" method.

b) By using the "Object.clone()" method.

c) By using the "Object.assign()" method.

d) JavaScript does not support object cloning.

Answer: c) By using the "Object.assign()" method.

What is the purpose of the "this" keyword in JavaScript?

a) To create a new object.

b) To refer to the current instance of a class.

c) To refer to the parent element in the DOM.

d) To terminate the execution of a function.

Answer: b) To refer to the current instance of a class.

What is the purpose of the "async" and "await" keywords in JavaScript?

a) To convert a function into an asynchronous function.

b) To perform mathematical calculations.

c) To define a function that returns a Promise.

d) To create animations and transitions on web pages.

Answer: a) To convert a function into an asynchronous function.

Write a JavaScript function to find the largest element in an array of numbers.

Write a JavaScript program to check if a given string is a palindrome.

Write a function that takes two arrays as input and returns their intersection (common elements).

Given a string, write a JavaScript function to count the occurrences of each character in the string.

Write a JavaScript program to find the sum of all prime numbers between 1 and N.
Write a function to flatten a nested array in JavaScript.

Given an array of integers, write a function to find the second smallest element.

Write a JavaScript program to generate the Fibonacci sequence up to a given number.

Write a function to check if a number is a perfect square or not in JavaScript.

Write a program to find the factorial of a given number using recursion in JavaScript.

What is JavaScript primarily used for?

a) Styling web pages

b) Creating interactive and dynamic web content

c) Database management

d) Web server configuration

Answer: b) Creating interactive and dynamic web content

Which keyword is used to declare variables in JavaScript?

a) var

b) let

c) const

d) all of the above

Answer: d) all of the above

What is the correct way to comment a single-line in JavaScript?

a) // This is a comment

b) <!-- This is a comment -->

c) /* This is a comment */

d) ## This is a comment

Answer: a) // This is a comment


Which built-in function is used to output content to the browser's developer console?

a) alert()

b) log()

c) print()

d) console.log()

Answer: d) console.log()

What is the purpose of the "querySelector" method in JavaScript?

a) To add event listeners to elements

b) To retrieve elements from the DOM using a CSS selector

c) To create new HTML elements dynamically

d) To set attributes for elements

Answer: b) To retrieve elements from the DOM using a CSS selector

You might also like