Computer

JavaScript & Front-End Frameworks MCQs with Answers

Which of the following is the correct way to declare a JavaScript variable?
a) var x;
b) int x;
c) let x;
d) Both a and c

Answer
d) Both a and c

Which of the following is used to define a function in JavaScript?
a) function()
b) func()
c) def()
d) method()

Answer
a) function()

What does the alert() function do in JavaScript?
a) Displays a pop-up message
b) Redirects to another page
c) Logs the message to the console
d) Refreshes the webpage

Answer
a) Displays a pop-up message

Which of the following methods is used to add an element to the end of an array in JavaScript?
a) push()
b) pop()
c) shift()
d) unshift()

Answer
a) push()

What is the purpose of console.log() in JavaScript?
a) To print output to the webpage
b) To display an alert message
c) To log messages in the console for debugging
d) To update the DOM

Answer
c) To log messages in the console for debugging

Which of the following is NOT a primitive data type in JavaScript?
a) String
b) Number
c) Object
d) Boolean

Answer
c) Object

How do you create an object in JavaScript?
a) var obj = {};
b) var obj = ();
c) var obj = [];
d) var obj = new Object();

Answer
a) var obj = {};

What will console.log(5 + ‘5’) output in JavaScript?
a) 55
b) 10
c) Error
d) 5 5

Answer
a) 55

Which of the following is the correct syntax to access an HTML element with the id “myElement” in JavaScript?
a) document.getElementById(“myElement”)
b) document.getElement(“myElement”)
c) getElementById(“myElement”)
d) document.getElementByClassName(“myElement”)

Answer
a) document.getElementById(“myElement”)

Which method is used to remove the last element of an array in JavaScript?
a) pop()
b) push()
c) shift()
d) unshift()

Answer
a) pop()

What does the setTimeout() function do in JavaScript?
a) Executes a function after a specified delay
b) Loops a function infinitely
c) Delays the loading of a webpage
d) Stops the execution of a function

Answer
a) Executes a function after a specified delay

Which of the following is a front-end JavaScript framework?
a) Django
b) Laravel
c) React
d) Flask

Answer
c) React

Which of the following JavaScript frameworks is primarily used for building mobile apps?
a) React
b) Angular
c) Vue
d) React Native

Answer
d) React Native

What is the use of localStorage in JavaScript?
a) To store data on the client-side persistently
b) To store data temporarily during a session
c) To store data on the server-side
d) To store data in cookies

Answer
a) To store data on the client-side persistently

Which of the following is true about promises in JavaScript?
a) A promise is a placeholder for a value that is available now
b) A promise is a placeholder for a value that is available in the future
c) A promise is a method used to handle errors
d) Promises are not used in asynchronous JavaScript

Answer
b) A promise is a placeholder for a value that is available in the future

Which of the following is used to handle routing in a React application?
a) Redux
b) React-Router
c) React-Query
d) Next.js

Answer
b) React-Router

What does JSX stand for in React?
a) JavaScript XML
b) JavaScript Extended
c) JavaScript Syntax Extension
d) JavaScript Style XML

Answer
a) JavaScript XML

What is the use of ngIf in Angular?
a) To repeat elements in the DOM
b) To conditionally render elements in the DOM
c) To bind event listeners
d) To manipulate styles dynamically

Answer
b) To conditionally render elements in the DOM

Which of the following is the default data binding method in Angular?
a) Two-way binding
b) One-way binding
c) Event binding
d) Property binding

Answer
b) One-way binding

What is the purpose of v-for in Vue.js?
a) To conditionally render elements
b) To loop over an array and render items
c) To bind events
d) To modify data in the DOM

Answer
b) To loop over an array and render items

Which JavaScript framework is known for its “MVVM” architecture?
a) React
b) Angular
c) Vue.js
d) Ember.js

Answer
c) Vue.js

What is the main difference between let and var in JavaScript?
a) let is function-scoped, while var is block-scoped
b) var is function-scoped, while let is block-scoped
c) let cannot be redeclared, while var can
d) var is a better choice for modern code

Answer
b) var is function-scoped, while let is block-scoped

Which of the following methods is used to update the state in a React component?
a) setState()
b) updateState()
c) changeState()
d) modifyState()

Answer
a) setState()

What is the main purpose of Webpack in a JavaScript project?
a) To manage APIs
b) To bundle JavaScript files
c) To optimize performance
d) To manage databases

Answer
b) To bundle JavaScript files

Which of the following is true about the virtual DOM in React?
a) It is a representation of the actual DOM in memory
b) It is slower than the actual DOM
c) It is not used for rendering React components
d) It directly manipulates the real DOM

Answer
a) It is a representation of the actual DOM in memory

What does the ngModel directive in Angular bind?
a) User input to a property
b) Events to a function
c) CSS styles to elements
d) API data to a variable

Answer
a) User input to a property

Which of the following is a popular JavaScript library for state management in React applications?
a) Vuex
b) Redux
c) MobX
d) Both b and c

Answer
d) Both b and c

What is the purpose of useEffect() in React?
a) To render the component
b) To update the component’s state
c) To run side effects in function components
d) To handle events

Answer
c) To run side effects in function components

Which of the following is used to send data from a Vue component to the parent component?
a) props
b) events
c) methods
d) state

Answer
a) props

Which CSS framework is most commonly used with JavaScript for front-end development?
a) Bootstrap
b) Tailwind CSS
c) Foundation
d) Bulma

Answer
a) Bootstrap

Which of the following methods is used to remove the first element from an array in JavaScript?
a) shift()
b) pop()
c) slice()
d) unshift()

Answer
a) shift()

What is the correct way to reference a class in CSS?
a) #class-name
b) .class-name
c) &class-name
d) class-name{}

Answer
b) .class-name

Which JavaScript function is used to check if a variable is an array?
a) isArray()
b) checkArray()
c) Array.isArray()
d) validateArray()

Answer
c) Array.isArray()

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button