How can you define optional route parameters in Express.js?
- Enclose parameters in square brackets [param]
- Use the optional keyword before the parameter
- Use the ? symbol after the parameter
- Wrap parameters in parentheses (param)
In Express.js, you can define optional route parameters by using the ? symbol after the parameter name, like /route/:param?. This makes the parameter optional, allowing it to match both routes with and without that parameter. The other options do not represent the correct way to define optional route parameters in Express.js.
Loading...
Related Quiz
- How does the placement of a package in dependencies or devDependencies affect the build process of a project?
- Which of the following is the correct syntax for destructuring an array in JavaScript?
- Which of the following is a suitable method to prevent variable leakage in the global scope?
- How can you extract route parameters in Express.js from a route URL like "/users/:userId"?
- Which of the following methods in JavaScript will remove the last element from an array and return that element?