Github Copilot · Free Practice Question Medium
Question 2
You are working on a Node.js project and need to write a function to handle user input validation. You want to explore different ways GitHub Copilot can suggest code snippets and variations for this task. What is the best approach to explore multiple suggestions from GitHub Copilot and refine the function for user input validation?
-
A
Use the keyboard shortcut to trigger multiple suggestions and cycle through different variations of the function from GitHub Copilot.
-
B
Invoke the exception handling feature to automatically resolve the need for input validation.
-
C
Rely on GitHub Copilot’s inline suggestions and manually rewrite the function based on the first suggestion it provides.
-
D
Use the GitHub Copilot CLI to search for user input validation examples and manually implement one of the options.
Reveal correct answer
Correct answer: A
A.
GitHub Copilot provides multiple code suggestions when invoked via the appropriate keyboard shortcut (e.g., pressing Ctrl+Enter or Alt+] in some IDEs). This allows you to cycle through different variations of the function and choose the one that best fits your requirements. It’s an efficient way to explore multiple options and refine the code.
B.
Exception handling is a different use case from input validation. Using exception handling does not inherently resolve validation needs. Instead, validating user input prevents errors from occurring, while exception handling deals with errors that happen despite validation.
C.
Relying solely on the first inline suggestion can limit creativity and may not provide the best solution. While Copilot's initial suggestion can be helpful, using the feature that generates multiple suggestions provides more flexibility in selecting the most appropriate solution.
D.
The GitHub Copilot CLI is not the most suitable tool for generating multiple code suggestions. While it can help automate commands and scripts, it is not the ideal interface for exploring multiple variations of a specific function. The IDE-based interface is more interactive for this purpose.
Discussion
Think the marked answer is wrong, or have a better explanation? Share it below — comments appear after review.
