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. V8
B. JavaScriptCore
C. SpiderMonkey
D. Chakra

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

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

3 Who created Node.js?

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

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. repl
B. npm start
C. js
D. node

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

A. module.exports
B. export default
C. return module
D. exports.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 handle and trigger events
B. To handle file operations
C. To handle HTTP requests
D. To stream data

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

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

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

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

18 Which method of EventEmitter causes an event to occur?

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

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

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

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

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

21 What is 'Callback Hell'?

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

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

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

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.appendFile()
B. fs.writeAfter()
C. fs.addFile()
D. fs.insert()

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

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

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

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

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

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

28 What is a Stream in Node.js?

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

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

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

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

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

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

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

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

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

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

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

34 What are the three states of a Promise?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

43 What is a 'Duplex' stream?

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

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

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

45 How can you install a package globally using npm?

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

46 What does 'npm' stand for?

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

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

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

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

A. The value is ignored
B. The next .then() receives it as a resolved value
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 are synchronous
B. Streams use less memory (memory efficiency)
C. Streams sort data automatically
D. Streams encrypt data automatically

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

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