Which fix removes the bug?
const name = ' Sara ';
if (name === 'Sara') {
greet();
}
- Compare
name.trim() === 'Sara'instead - Compare
name.trimAll() === 'Sara'instead - Change
===to==in the condition - Wrap the name in
String(name)first
The surrounding spaces make the strings differ; trim before comparing.
Play Problem Solving ▸