Docsity

OpenJS Foundation JavaScriptLandia Practice Exam, Exams of Technology

Toggle sidebar
bg1
OpenJS Foundation JavaScriptLandia
Practice Exam
**Question 1. Which Buffer method creates a new Buffer containing a copy of the data from an
existing Buffer?**
A) Buffer.concat()
B) Buffer.from()
C) Buffer.alloc()
D) Buffer.slice()
Answer: B
Explanation: Buffer.from() creates a new Buffer that copies the contents of the supplied source
(string, array, or another Buffer).
**Question 2. In a readable stream, which event is emitted when there is no more data to be
read?**
A) 'data'
B) 'end'
C) 'close'
D) 'finish'
Answer: B
Explanation: The 'end' event signals that the readable stream has emitted all its data and will
not emit more.
**Question 3. Which of the following best describes a Transform stream?**
A) A stream that can only read data
B) A stream that can only write data
C) A duplex stream that can modify data as it passes through
D) A stream that buffers all data before emitting it
Answer: C
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c

Partial preview of the text

Download OpenJS Foundation JavaScriptLandia Practice Exam and more Exams Technology in PDF only on Docsity!

Practice Exam

Question 1. Which Buffer method creates a new Buffer containing a copy of the data from an existing Buffer? A) Buffer.concat() B) Buffer.from() C) Buffer.alloc() D) Buffer.slice() Answer: B Explanation: Buffer.from() creates a new Buffer that copies the contents of the supplied source (string, array, or another Buffer). Question 2. In a readable stream, which event is emitted when there is no more data to be read? A) 'data' B) 'end' C) 'close' D) 'finish' Answer: B Explanation: The 'end' event signals that the readable stream has emitted all its data and will not emit more. Question 3. Which of the following best describes a Transform stream? A) A stream that can only read data B) A stream that can only write data C) A duplex stream that can modify data as it passes through D) A stream that buffers all data before emitting it Answer: C

Practice Exam

Explanation: Transform streams are duplex streams that implement both read and write methods, allowing data to be transformed during the flow. Question 4. What does the pipe() method return when chaining streams? A) The destination writable stream B) The source readable stream C) An array of all streams in the chain D) Nothing (undefined) Answer: A Explanation: pipe() returns the destination stream, enabling further chaining of additional pipe calls. Question 5. Which of the following is NOT a valid way to create a Buffer of a specific size? A) Buffer.alloc(10) B) Buffer.allocUnsafe(10) C) Buffer.from(10) D) Buffer.allocUnsafeSlow(10) Answer: C Explanation: Buffer.from() creates a Buffer from existing data; it does not allocate a buffer of a given size. Question 6. When using async/await, which keyword must precede a function declaration to enable the use of await inside it? A) async B) defer C) promise

Practice Exam

B) Nesting multiple callbacks inside each other C) Using async/await syntax D) Using EventEmitter listeners Answer: B Explanation: Deeply nested callbacks create hard‑to‑read code, commonly referred to as “callback hell”. Question 10. Which Node.js method spawns a new process that runs a command with a shell and buffers the output? A) child_process.spawn() B) child_process.exec() C) child_process.fork() D) child_process.execFile() Answer: B Explanation: exec() runs a command in a shell and buffers the output for later use. Question 11. Which child_process method is most suitable for creating a new Node.js instance that can communicate via IPC? A) spawn() B) exec() C) execFile() D) fork() Answer: D Explanation: fork() spawns a new Node.js process with an established IPC channel for message passing.

Practice Exam

Question 12. In a child process created with spawn(), which stdio option value would allow you to pipe the child’s stdout to the parent’s process? A) 'ignore' B) 'inherit' C) 'pipe' D) 'ipc' Answer: C Explanation: Setting stdio to 'pipe' creates a stream that can be read from the parent process. Question 13. Which command-line flag disables V8’s deoptimization of functions for debugging purposes? A) --inspect B) --no-deprecation C) --trace-deprecation D) --no-optimize-for-size Answer: A Explanation: The --inspect flag enables the V8 inspector, which disables certain optimizations to allow accurate debugging. Question 14. In Visual Studio Code, which shortcut starts a debugging session for a Node.js application? A) F B) Ctrl+Shift+P C) Ctrl+` D) F Answer: A

Practice Exam

D) RangeError Answer: A Explanation: Extending the generic Error class is the standard way to create custom error types. Question 18. What event is emitted when an unhandled promise rejection occurs? A) 'uncaughtException' B) 'unhandledRejection' C) 'rejectionHandled' D) 'error' Answer: B Explanation: The process object emits 'unhandledRejection' when a promise is rejected and no catch handler is attached. Question 19. Which Node.js command‑line flag enables experimental ES module support without the .mjs extension? A) --experimental-modules B) --es-module-specifier-resolution=node C) --no-warnings D) --trace-warnings Answer: A Explanation: The --experimental-modules flag allows using ES modules with .js files (subject to package.json type field). Question 20. Which npm package is commonly used to build command‑line interfaces with argument parsing? A) express

Practice Exam

B) commander C) jest D) lodash Answer: B Explanation: commander provides a fluent API for defining commands, options, and parsing CLI arguments. Question 21. Which method of EventEmitter removes all listeners for a specific event? A) off(event) B) removeAllListeners(event) C) deleteListeners(event) D) clear(event) Answer: B Explanation: removeAllListeners(event) clears every listener attached to the given event name. Question 22. In EventEmitter, what is the default maximum number of listeners for a single event before a warning is emitted? A) 5 B) 10 C) 15 D) Unlimited Answer: B Explanation: Node.js emits a warning when more than 10 listeners are added to a single event, to help detect memory leaks. Question 23. Which of the following statements about the 'error' event is true?

Practice Exam

Question 26. Which path method resolves a sequence of path segments into an absolute path? A) path.join() B) path.normalize() C) path.resolve() D) path.basename() Answer: C Explanation: path.resolve() processes the sequence from right to left, returning an absolute path. Question 27. In Node.js, what does the mode argument of fs.open() control? A) File encoding B) File descriptor number C) File permissions (read/write/execute) D) Buffer size Answer: C Explanation: The mode argument sets the file’s permission bits, similar to the UNIX chmod values. Question 28. Which of the following is a valid way to import a CommonJS module? A) import myModule from './myModule'; B) const myModule = require('./myModule'); C) const { myModule } = import('./myModule'); D) import * as myModule from './myModule'; Answer: B Explanation: CommonJS uses require() to load modules synchronously.

Practice Exam

Question 29. Which statement correctly imports the default export from an ES module? A) const myModule = require('./myModule.js'); B) import myModule from './myModule.js'; C) import * as myModule from './myModule.js'; D) const { default: myModule } = require('./myModule.js'); Answer: B Explanation: The ES module syntax uses import defaultExport from 'module'. Question 30. When Node.js resolves a module, which field in package.json can specify the entry point for ES modules? A) main B) module C) exports D) type Answer: C Explanation: The "exports" field defines conditional entry points for different module formats, including ESM. Question 31. Which process property contains the command‑line arguments passed to a Node.js script? A) process.env B) process.argv C) process.execPath D) process.cwd() Answer: B

Practice Exam

Answer: B Explanation: Arrow functions cannot be used with new because they lack a [[Construct]] method. Question 35. Which syntax correctly uses destructuring to extract the status property from an object response? A) const { status } = response; B) const [ status ] = response; C) const status = response.status; D) const status = { response }.status; Answer: A Explanation: Object destructuring with curly braces extracts named properties. Question 36. In Node.js, what does the spread operator (...) do when used in a function call? A) Merges two objects into one. B) Expands an iterable into individual arguments. C) Creates a shallow copy of an array. D) Captures remaining arguments into an array. Answer: B Explanation: Using ... before an iterable spreads its elements as separate arguments. Question 37. Which of the following correctly defines a template literal that includes a variable name? A) "Hello, ${name}" B) "'Hello, ${name}'"

Practice Exam

C) "Hello, ${ name }" D) Both A and C Answer: D Explanation: Template literals use backticks and ${} for interpolation; whitespace inside the braces is ignored. Question 38. Which of these statements about the this keyword inside a regular function called as a method is true? A) It refers to the global object. B) It is undefined in strict mode. C) It refers to the object the method belongs to. D) It always refers to the module.exports object. Answer: C Explanation: When a function is invoked as a property of an object, this points to that object. Question 39. Which statement correctly creates a read‑only property on an object using Object.defineProperty? A) Object.defineProperty(obj, 'prop', { value: 42, writable: false }); B) Object.defineProperty(obj, 'prop', { value: 42, readOnly: true }); C) Object.defineProperty(obj, 'prop', { get: () => 42 }); D) Both A and C Answer: D Explanation: Setting writable: false makes the property read‑only; a getter without a setter also creates a read‑only virtual property.

Practice Exam

Explanation: 201 Created signals that the server has successfully created a new resource. Question 43. In Express, which method adds a middleware that will be executed for every request regardless of path? A) app.use() B) app.all() C) app.get() D) app.post() Answer: A Explanation: app.use() registers middleware for all routes and HTTP verbs. Question 44. Which Express method is used to define a route that responds to HTTP DELETE requests? A) app.del() B) app.remove() C) app.delete() D) app.destroy() Answer: C Explanation: app.delete() registers a handler for DELETE requests. Question 45. Which of the following is the correct way to parse JSON bodies in an Express application? A) app.use(express.json()); B) app.use(bodyParser.json()); C) app.use(require('json-parser')()); D) Both A and B (assuming body-parser is installed)

Practice Exam

Answer: D Explanation: Both express.json() (built‑in) and bodyParser.json() (external) parse JSON request bodies. Question 46. Which HTTP header is commonly used to prevent Cross‑Site Request Forgery attacks? A) X-Content-Type-Options B) X-XSS-Protection C) X-CSRF-Token D) Set-Cookie with SameSite attribute Answer: D Explanation: Setting the SameSite attribute on cookies restricts cross‑origin requests, mitigating CSRF. Question 47. Which npm package is widely used to validate and sanitize user input in Node.js applications? A) validator B) joi C) sanitize-html D) All of the above Answer: D Explanation: All listed packages provide validation/sanitization utilities; joi is especially popular for schema‑based validation. Question 48. Which of the following headers tells browsers to only communicate with the server over HTTPS? A) Content-Security-Policy

Practice Exam

Question 51. Which status code should be returned when a client sends malformed JSON in the request body? A) 400 Bad Request B) 401 Unauthorized C) 415 Unsupported Media Type D) 422 Unprocessable Entity Answer: A Explanation: 400 indicates that the request could not be understood due to malformed syntax. Question 52. Which of the following best describes rate limiting in an API? A) Blocking all requests after a certain time. B) Limiting the number of requests per client within a time window. C) Encrypting request payloads. D) Caching responses for faster delivery. Answer: B Explanation: Rate limiting caps the number of allowed requests from a client to protect against abuse. Question 53. Which npm package can automatically scan your dependencies for known vulnerabilities? A) npm audit B) snyk C) retire.js D) All of the above Answer: D

Practice Exam

Explanation: npm audit, Snyk, and retire.js all provide vulnerability scanning of package dependencies. Question 54. Which CORS response header allows any origin to access the resource? A) Access-Control-Allow-Origin: * B) Access-Control-Allow-Methods: * C) Access-Control-Allow-Credentials: true D) Access-Control-Expose-Headers: * Answer: A Explanation: Setting Access-Control-Allow-Origin to * permits all origins. Question 55. In Node.js, which property of the request object contains the parsed query string as an object when using the built‑in http module? A) req.query B) req.url C) req.searchParams D) None; you must parse it manually or use a framework. Answer: D Explanation: The core http module does not parse query strings; you need to use URL module or a framework. Question 56. Which of the following is the correct way to create a JWT token using the jsonwebtoken package? A) jwt.sign(payload, secret, { expiresIn: '1h' }); B) jwt.encode(payload, secret); C) jwt.create(payload, secret);