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. Multi-threaded and non-blocking
B. Multi-threaded and blocking
C. Single-threaded and blocking
D. Single-threaded and non-blocking

3 Who created Node.js?

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 and trigger events
C. To handle file operations
D. To handle HTTP requests

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

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

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

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

18 Which method of EventEmitter causes an event to occur?

A. fire()
B. dispatch()
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. A syntax error in callbacks
B. Deeply nested callbacks making code hard to read
C. When a callback never executes
D. A security vulnerability

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

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

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

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

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

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

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.toString()
B. JSON.stringify()
C. JSON.parse()
D. JSON.convert()

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

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

28 What is a Stream in Node.js?

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

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

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

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

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

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

A. url
B. path
C. fs
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.compress()
B. zlib.zip()
C. zlib.gzip()
D. zlib.createGzip()

34 What are the three states of a Promise?

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

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

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

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

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

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. Synchronous functions
B. Callback functions
C. Any function
D. async functions

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

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

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

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

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

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

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

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

43 What is a 'Duplex' stream?

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

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

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

45 How can you install a package globally using npm?

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

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. close
B. done
C. finish
D. end

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

A. It throws an error
B. The value is ignored
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 sort data automatically
B. Streams encrypt 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. http
B. url
C. fs
D. net