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

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

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

3 Who created Node.js?

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

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

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

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

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

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

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

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

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

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

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

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. node_modules
B. config.xml
C. index.js
D. package.json

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

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

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

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

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

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

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

18 Which method of EventEmitter causes an event to occur?

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

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

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

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

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

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.open()
B. fs.read()
C. fs.readFile()
D. fs.readFileSync()

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

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

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

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

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

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

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

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

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

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

28 What is a Stream in Node.js?

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

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 connect a readable stream to a writable stream
B. To pause the stream
C. To convert stream to buffer
D. To delete the stream

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

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

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

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

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

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

34 What are the three states of a Promise?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

43 What is a 'Duplex' stream?

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

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

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

45 How can you install a package globally using npm?

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

46 What does 'npm' stand for?

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

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

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

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

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

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

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

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

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