Bird
0
0

What is wrong with this JavaScript code?

medium📝 Analysis Q7 of 15
Intro to Computing - How Files and Folders Organize Data
What is wrong with this JavaScript code?
let fruits = ['apple', 'banana', 'cherry'];
console.log(fruits.find('banana'));
ASyntax error in console.log
Bfind() requires a function, not a value
CArray is empty
Dbanana is not in the array
Step-by-Step Solution
Solution:
  1. Step 1: Understand how find() works in JavaScript

    find() expects a function that returns true for the desired element, not a direct value.
  2. Step 2: Check if other options apply

    The array is not empty, syntax is correct, and 'banana' is in the array.
  3. Final Answer:

    find() requires a function, not a value -> Option B
  4. Quick Check:

    JS find() needs a callback function [OK]
Quick Trick: Use find() with a function, not a direct value [OK]
Common Mistakes:
  • Passing value directly to find()
  • Thinking array is empty
  • Misreading console.log syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Intro to Computing Quizzes