Notice: Due to an ongoing migration of our storage and publishing system, material requested since last month will not be uploaded for the time being, and new requests are paused. All existing notes remain available.
You're offline
Unit 1 MCQsRefreshing JavaScript and ReactJS installation
In ES6, which keyword is used to declare a variable that cannot be reassigned?
Not quite. Try another option.
Answer: const
The 'const' keyword is used to declare variables that are meant to remain constant and cannot be reassigned after their initial declaration.
Question 2 of 50
What is the scope of a variable declared using the 'let' keyword?
Not quite. Try another option.
Answer: Block scope
Variables declared with 'let' are limited to the block, statement, or expression on which it is used, unlike 'var' which is function scoped.
Question 3 of 50
Which of the following is the correct syntax for an Arrow Function in ES6?
Not quite. Try another option.
Answer: const name = () => {}
Arrow functions use the '=>' syntax. A common way to define them is assigning them to a constant.
Question 4 of 50
How does the 'this' keyword behave differently in Arrow Functions compared to regular functions?
Not quite. Try another option.
Answer: It inherits 'this' from the surrounding code (lexical scoping)
Arrow functions do not have their own 'this'. They inherit 'this' from the parent scope at the time they are defined.
Question 5 of 50
Which Array method creates a new array by applying a function to every element in the calling array?
Not quite. Try another option.
Answer: map
The map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
Question 6 of 50
What does the Array.prototype.filter() method return?
Not quite. Try another option.
Answer: A new array with all elements that pass the test
filter() creates a shallow copy of a portion of a given array, filtered down to just the elements from the given array that pass the test implemented by the provided function.
Question 7 of 50
Which method checks if all elements in an array pass a specific test?
Not quite. Try another option.
Answer: every()
The every() method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
Question 8 of 50
What is the primary purpose of the Array.prototype.reduce() method?
Not quite. Try another option.
Answer: To reduce the array to a single value
The reduce() method executes a reducer function on each element of the array, resulting in a single output value.
Question 9 of 50
Which ES6 feature allows you to unpack values from arrays or properties from objects into distinct variables?
Not quite. Try another option.
Answer: Destructuring
Destructuring assignment is a syntax that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.
Question 10 of 50
What is the output of the following code: const [a, b] = [1, 2]; console.log(b);?
Not quite. Try another option.
Answer: 2
This is array destructuring. The variable 'b' is assigned the second value of the array, which is 2.
Question 11 of 50
Which operator is indicated by three dots (...) and expands an iterable into individual elements?
Not quite. Try another option.
Answer: Spread Operator
The Spread operator (...) allows an iterable such as an array or string to be expanded in places where zero or more arguments or elements are expected.
Question 12 of 50
In the context of function arguments, what does the Rest operator (...) do?
Not quite. Try another option.
Answer: Collects multiple arguments into a single array
The Rest parameter syntax allows a function to accept an indefinite number of arguments as an array.
Question 13 of 50
How do you define a class in ES6?
Not quite. Try another option.
Answer: class MyClass {}
ES6 introduced the 'class' keyword to define classes, which is primarily syntactical sugar over JavaScript's existing prototype-based inheritance.
Question 14 of 50
Which keyword is used to inherit a class from another class?
Not quite. Try another option.
Answer: extends
The 'extends' keyword is used in class declarations or class expressions to create a class that is a child of another class.
Question 15 of 50
What is the purpose of the 'export default' syntax in ES6 Modules?
Not quite. Try another option.
Answer: To export a single main value from a module
export default is used to export a single class, function, or primitive from a script file, which can be imported without using curly braces.
Question 16 of 50
How do you import a named export 'data' from a module 'file.js'?
Not quite. Try another option.
Answer: import { data } from './file.js'
Named exports must be imported using curly braces matching the export name.
Question 17 of 50
Which method creates a new Array instance from an array-like or iterable object?
Not quite. Try another option.
Answer: Array.from()
Array.from() lets you create Arrays from array-like objects (objects with a length property and indexed elements) or iterable objects.
Question 18 of 50
What does the Array.prototype.find() method return?
Not quite. Try another option.
Answer: The first element satisfying the condition
The find() method returns the first element in the provided array that satisfies the provided testing function. If no values satisfy the testing function, undefined is returned.
Question 19 of 50
The Array.prototype.concat() method is used to:
Not quite. Try another option.
Answer: Merge two or more arrays
The concat() method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
Question 20 of 50
What is a Single Page Application (SPA)?
Not quite. Try another option.
Answer: An app that dynamically rewrites the current web page with new data from the web server
An SPA interacts with the user by dynamically rewriting the current web page with new data from the web server, rather than the default method of the browser loading entire new pages.
Question 21 of 50
What is a major difference between SPA and MPA (Multi-Page Application)?
Not quite. Try another option.
Answer: MPA reloads the page for every request, SPA does not
In an MPA, the browser downloads a fresh page on every interaction. In an SPA, the page does not reload; content is updated dynamically via JavaScript.
Question 22 of 50
Which company maintains ReactJS?
Not quite. Try another option.
Answer: Facebook (Meta)
React is an open-source front-end JavaScript library for building user interfaces or UI components maintained by Facebook (Meta).
Question 23 of 50
What is the standard command to create a new React project using Create React App?
Not quite. Try another option.
Answer: npx create-react-app my-app
npx create-react-app my-app is the standard command to scaffold a new React project using the Create React App tool.
Question 24 of 50
Which build tool is known for being faster than Webpack and is often used as an alternative to Create React App?
Not quite. Try another option.
Answer: Vite
Vite is a build tool that significantly improves the frontend development experience, offering faster server start and hot module replacement compared to Webpack (used by CRA).
Question 25 of 50
Which folder in a React project structure typically contains images, index.html, and the manifest file?
Not quite. Try another option.
Answer: public
The 'public' folder contains static assets like the HTML file and images that are not processed by Webpack's module system.
Question 26 of 50
In a standard React folder structure, where does the source code (components, styles) primarily reside?
Not quite. Try another option.
Answer: src
The 'src' (source) directory is where the developer writes the React components, CSS, and application logic.
Question 27 of 50
What is 'node_modules' in a React environment?
Not quite. Try another option.
Answer: The folder containing all installed npm dependencies
node_modules is the repository where npm or yarn stores the external libraries and packages required by the project.
Question 28 of 50
What does JSX stand for?
Not quite. Try another option.
Answer: JavaScript XML
JSX stands for JavaScript XML. It is a syntax extension for JavaScript that looks similar to XML or HTML.
Question 29 of 50
Can browsers understand JSX directly?
Not quite. Try another option.
Answer: No, it must be transpiled to regular JavaScript
Browsers cannot read JSX. It needs to be transformed into standard JavaScript objects (using tools like Babel) before the browser can understand it.
Question 30 of 50
In React, what is the equivalent of the HTML 'class' attribute in JSX?
Not quite. Try another option.
Answer: className
Since 'class' is a reserved keyword in JavaScript, JSX uses 'className' to define CSS classes for elements.
Question 31 of 50
What method is strictly used to render a React element into the DOM in older React versions (before React 18)?
Not quite. Try another option.
Answer: ReactDOM.render()
ReactDOM.render() was the standard method to render React components into the DOM before React 18 introduced createRoot.
Question 32 of 50
Which function is implicitly called when you write JSX tags?
Not quite. Try another option.
Answer: React.createElement
JSX code is compiled into calls to React.createElement().
Question 33 of 50
What are the first three arguments of React.createElement()?
Not quite. Try another option.
Answer: type, props, children
The signature is React.createElement(type, [props], [...children]). Type is the tag name, props are attributes, and children are content.
Question 34 of 50
How do you embed a JavaScript expression inside JSX?
Not quite. Try another option.
Answer: Inside curly braces { }
Curly braces { } are used to embed valid JavaScript expressions, variables, or logic within JSX.
Question 35 of 50
Which of the following is a valid way to write an inline style in JSX?
Not quite. Try another option.
Answer: style={{ color: "red" }}
In JSX, the style attribute accepts a JavaScript object. The outer braces represent the JSX expression, and the inner braces denote the object.
Question 36 of 50
Component names in React must start with:
Not quite. Try another option.
Answer: An uppercase letter
React treats components starting with lowercase letters as DOM tags. User-defined components must be capitalized.
Question 37 of 50
What is the main advantage of using JSX over React.createElement?
Not quite. Try another option.
Answer: It provides a visual structure that is easier to read and write
While both do the same thing ultimately, JSX is syntactic sugar that allows developers to visualize the UI structure similarly to HTML, making code more readable.
Question 38 of 50
If you want to render a list of items in React, which array method is most commonly used?
Not quite. Try another option.
Answer: map
The map() method is used to iterate over an array of data and return an array of React elements (JSX).
Question 39 of 50
What acts as the entry point to a React application created with Vite?
Not quite. Try another option.
Answer: main.jsx
In Vite projects, the entry point is typically named 'main.jsx' (or 'main.tsx' for TypeScript), which mounts the app.
Question 40 of 50
Which file typically contains the root DOM node <div id="root"></div>?
Not quite. Try another option.
Answer: index.html
The public/index.html file contains the HTML boilerplate and the empty div with id='root' where React attaches the application.
Question 41 of 50
In React, tags with no children (self-closing tags) must end with:
Not quite. Try another option.
Answer: />
In JSX, self-closing tags must explicitly end with '/>', unlike HTML where the slash is optional for void elements.
Question 42 of 50
What is the correct way to wrap multiple elements in JSX without adding an extra node to the DOM?
Not quite. Try another option.
Answer: <Fragment> or <>
React Fragments (<React.Fragment> or the short syntax <>) let you group a list of children without adding extra nodes to the DOM.
Question 43 of 50
What is the return type of a functional component?
Not quite. Try another option.
Answer: JSX
Functional components return JSX, which describes what the UI should look like.
Question 44 of 50
Which environment is required to run the 'create-react-app' command?
Not quite. Try another option.
Answer: Node.js
Node.js is the runtime environment required to execute npm/npx commands and run the development server.
Question 45 of 50
What is the purpose of package.json in a React project?
Not quite. Try another option.
Answer: It lists project dependencies and scripts
package.json acts as the manifest for the project, recording metadata, scripts (like start, build), and dependencies.
Question 46 of 50
What does the Array.prototype.reverse() method do?
Not quite. Try another option.
Answer: Reverses the order of elements in place
The reverse() method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.
Question 47 of 50
How do you comment inside JSX?
Not quite. Try another option.
Answer: {/ comment /}
Inside the JSX return block, comments must be wrapped in curly braces and use block comment syntax: {/ comment /}.
Question 48 of 50
What happens if you try to render a Boolean value (true/false) in JSX?
Not quite. Try another option.
Answer: It renders nothing
React does not render true, false, null, or undefined in the DOM. They are ignored.
Question 49 of 50
Which attribute is used in JSX to handle the 'for' attribute of labels?
Not quite. Try another option.
Answer: htmlFor
'for' is a reserved word in JavaScript (for loops), so React uses 'htmlFor' to associate a label with an input.
Question 50 of 50
The 'forEach' array method returns:
Not quite. Try another option.
Answer: undefined
forEach executes a provided function once for each array element but does not return anything (returns undefined). It is used for side effects.
That's unit 1
Answer a few questions and your score shows up here.
Nearly through. Did unit 1 of INT252 save you a night before the exam?
LPU Notes is free. A student pays for the servers.
Did unit 1 of INT252 save you a night before the exam?
Then you can help keep it free for the next batch. Ads cover part of the server bill;
the rest comes out of a student's own pocket: the domain, the storage, and keeping
the site up through the weeks everyone needs it at once.
The payment button didn't load. An ad blocker or a filtered network is the usual reason.
to try again.