Unit 1 - Practice Quiz

INT222 50 Questions
0 Correct 0 Wrong 50 Left
0/50

1 Which JavaScript engine is Node.js built upon?

A. SpiderMonkey
B. V8
C. JavaScriptCore
D. Chakra

2 Which of the following best describes the nature of Node.js?

A. Multi-threaded and non-blocking
B. Multi-threaded and blocking
C. Single-threaded and non-blocking
D. Single-threaded and blocking

3 Who created Node.js?

A. Jordan Walke
B. Brendan Eich
C. Tim Berners-Lee
D. Ryan Dahl

4 What does REPL stand for in the context of Node.js?

A. Read Eval Print Loop
B. Read Execute Process List
C. Run Execute Print Loop
D. Read Evaluate Process Loop

5 Which command allows you to enter the Node.js REPL environment in a terminal?

A. js
B. repl
C. node
D. npm start

6 In the Node.js REPL, what does the underscore variable (_) represent?

A. The last evaluated result
B. The global scope
C. An undefined variable
D. The current directory

7 Which command is used to initialize a new Node.js project and create a package.json file?

A. npm new
B. npm install
C. npm init
D. npm start

8 Which flag can be used with 'npm init' to skip the questionnaire and use default values?

A. --default
B. -y
C. --skip
D. -f

9 Where does npm install the dependencies for a local project by default?

A. node_modules
B. /usr/local/lib
C. global_modules
D. npm_packages

10 Which file stores the metadata and dependency list for a Node.js project?

A. package.json
B. index.js
C. node_modules
D. config.xml

11 Which function is used to include modules in Node.js?

A. require()
B. include()
C. import()
D. fetch()

12 Which of the following is a Core Module in Node.js?

A. express
B. lodash
C. fs
D. mongoose

13 How do you export a function or object from a module in Node.js using CommonJS?

A. module.exports
B. exports.module
C. export default
D. return module

14 Which syntax is correct to import a local module located in the same directory?

A. import moduleName
B. require('moduleName')
C. require('/moduleName')
D. require('./moduleName')

15 What is the purpose of the 'events' module in Node.js?

A. To stream data
B. To handle HTTP requests
C. To handle and trigger events
D. To handle file operations

16 Which class is the primary component of the 'events' module?

A. EventHandler
B. EventListener
C. EventDispatcher
D. EventEmitter

17 Which method of EventEmitter is used to register a listener for an event?

A. on()
B. listen()
C. emit()
D. trigger()

18 Which method of EventEmitter causes an event to occur?

A. call()
B. dispatch()
C. emit()
D. fire()

19 What is a 'callback' in Node.js?

A. A global variable
B. A function passed as an argument to be executed later
C. A recursive loop
D. A blocking function

20 What is the convention for the first argument of a Node.js callback function?

A. The result data
B. The callback function itself
C. The error object (or null)
D. The configuration object

21 What is 'Callback Hell'?

A. Deeply nested callbacks making code hard to read
B. A security vulnerability
C. A syntax error in callbacks
D. When a callback never executes

22 Which method is used to read a file asynchronously in Node.js?

A. fs.readFileSync()
B. fs.readFile()
C. fs.read()
D. fs.open()

23 What happens if you use 'fs.writeFile()' on an existing file?

A. It replaces the file content
B. It throws an error
C. It creates a backup copy
D. It appends data to the end

24 Which 'fs' method is used to add data to a file without overwriting it?

A. fs.addFile()
B. fs.writeAfter()
C. fs.appendFile()
D. fs.insert()

25 How do you delete a file using the 'fs' module?

A. fs.delete()
B. fs.remove()
C. fs.unlink()
D. fs.erase()

26 Which method converts a JavaScript object into a JSON string?

A. JSON.convert()
B. JSON.toString()
C. JSON.stringify()
D. JSON.parse()

27 Which method parses a JSON string into a JavaScript object?

A. JSON.stringify()
B. JSON.parse()
C. JSON.objectify()
D. JSON.decode()

28 What is a Stream in Node.js?

A. A large file stored in memory
B. A static HTML page
C. A database connection
D. A continuous flow of data handled piece by piece

29 Which type of stream can generally be used to read data from a source?

A. Readable
B. Transform
C. Duplex
D. Writable

30 What is the purpose of the 'pipe()' method in streams?

A. To convert stream to buffer
B. To connect a readable stream to a writable stream
C. To pause the stream
D. To delete the stream

31 Which module allows you to work with file paths specifically?

A. url
B. http
C. fs
D. path

32 Which Node.js module provides compression and decompression functionality?

A. crypto
B. compress
C. zip
D. zlib

33 Which function creates a stream that compresses data using Gzip?

A. zlib.createGzip()
B. zlib.compress()
C. zlib.zip()
D. zlib.gzip()

34 What are the three states of a Promise?

A. True, False, Null
B. Running, Waiting, Dead
C. Pending, Fulfilled, Rejected
D. Start, Stop, Pause

35 Which method is used to handle the successful resolution of a Promise?

A. .then()
B. .catch()
C. .done()
D. .finally()

36 Which method is used to catch errors in a Promise chain?

A. .then()
B. .error()
C. .catch()
D. .fail()

37 What does the 'async' keyword do when placed before a function?

A. It ensures the function returns a Promise
B. It pauses the event loop
C. It makes the function run in a separate thread
D. It makes the function synchronous

38 The 'await' keyword can only be used inside which type of function?

A. Any function
B. Synchronous functions
C. async functions
D. Callback functions

39 What is the benefit of using async/await over callbacks?

A. It bypasses the V8 engine
B. It creates multi-threading
C. It runs faster
D. It writes asynchronous code that looks synchronous and is easier to read

40 What is the global object in Node.js equivalent to 'window' in browsers?

A. document
B. process
C. global
D. root

41 Which global variable holds the directory name of the current module?

A. process.cwd()
B. module.path
C. __filename
D. __dirname

42 Which method checks if a file exists in Node.js (Modern approach)?

A. fs.access()
B. fs.validate()
C. fs.exists()
D. fs.check()

43 What is a 'Duplex' stream?

A. A stream that compresses data
B. A stream that can both read and write
C. A stream that can only read
D. A stream that can only write

44 What is the file extension typically used for a file containing CommonJS module code?

A. .mjs
B. .js
C. .json
D. .ts

45 How can you install a package globally using npm?

A. npm global install package
B. npm add package global
C. npm install package --all
D. npm install package -g

46 What does 'npm' stand for?

A. Node Process Manager
B. New Package Module
C. Node Package Manager
D. Node Project Manager

47 When using 'fs.createReadStream', which event is fired when the file is completely read?

A. end
B. finish
C. done
D. close

48 In a Promise, what happens if you return a value in a .then() block?

A. The next .then() receives it as a resolved value
B. The value is ignored
C. The promise chain stops
D. It throws an error

49 What is the main advantage of Streams over reading files into memory?

A. Streams encrypt data automatically
B. Streams sort data automatically
C. Streams use less memory (memory efficiency)
D. Streams are synchronous

50 Which core module allows you to create a web server?

A. url
B. fs
C. http
D. net