Bird
0
0

Given the file data.json contains {"name":"Alice"}, what will this code log?

medium📝 Predict Output Q4 of 15
Cypress - File Operations
Given the file data.json contains {"name":"Alice"}, what will this code log?
cy.readFile('data.json').then((content) => {
console.log(content.name)
})
A{"name":"Alice"}
BAlice
CError: content is not defined
Dundefined
Step-by-Step Solution
Solution:
  1. Step 1: Understand JSON file reading

    cy.readFile parses JSON files automatically into objects.
  2. Step 2: Access the 'name' property

    content is the parsed object, so content.name returns 'Alice'.
  3. Final Answer:

    Alice -> Option B
  4. Quick Check:

    JSON parsed = content.name is 'Alice' [OK]
Quick Trick: JSON files auto-parsed; access properties directly [OK]
Common Mistakes:
  • Expecting raw JSON string instead of parsed object
  • Trying to access content before promise resolves
  • Confusing console.log output with error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Cypress Quizzes