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

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

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

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()

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

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

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

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

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”)

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

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

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

Which of the following JavaScript frameworks is primarily used for building mobile apps?
a) React
b) Angular
c) Vue
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

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

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

What does JSX stand for in React?
a) JavaScript XML
b) JavaScript Extended
c) JavaScript Syntax Extension
d) JavaScript Style 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

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

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

Which JavaScript framework is known for its “MVVM” architecture?
a) React
b) Angular
c) Vue.js
d) Ember.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

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

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

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

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

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

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

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

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

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()

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

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

Related Articles

Leave a Reply

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

Back to top button