How do you provide default values for prompts?

Prepare for the Yeoman (YN) Test. Use flashcards and multiple-choice questions, all with hints and explanations, to get ready for your upcoming exam. Enhance your learning experience!

Multiple Choice

How do you provide default values for prompts?

Explanation:
Providing default values is done by setting a default property on each prompt. This ties the fallback directly to the question being asked, so the user sees the suggested value right where they enter their answer and that value is used automatically if they just press Enter. It keeps defaults self-contained and easy to maintain, since you can read the expected value for a prompt at a glance and modify it alongside the prompt definition. For example, you might have a prompt like: a type of input, named projectName, with a message asking for the project name and a default of "my-app". This ensures that if the user doesn’t type anything, "my-app" is used as the answer. Using a separate defaults file would add extra wiring to merge those values into the prompts, making the generator harder to understand and maintain. Putting defaults in package.json isn’t the standard approach for Yeoman prompts, and defaults aren’t ignored in Yeoman—they’re meant to be the usual fallback.

Providing default values is done by setting a default property on each prompt. This ties the fallback directly to the question being asked, so the user sees the suggested value right where they enter their answer and that value is used automatically if they just press Enter. It keeps defaults self-contained and easy to maintain, since you can read the expected value for a prompt at a glance and modify it alongside the prompt definition.

For example, you might have a prompt like: a type of input, named projectName, with a message asking for the project name and a default of "my-app". This ensures that if the user doesn’t type anything, "my-app" is used as the answer.

Using a separate defaults file would add extra wiring to merge those values into the prompts, making the generator harder to understand and maintain. Putting defaults in package.json isn’t the standard approach for Yeoman prompts, and defaults aren’t ignored in Yeoman—they’re meant to be the usual fallback.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy