Report whether a string and a number are loosely equal.
Acceptance criteria
- 1.#out should show loosely equal.
JavaScript Tutorial · JavaScript Type System
These 10 tasks go with the JavaScript == vs === chapter. 5 of them ask you to build something small from scratch; 5 give you code that is already broken and ask you to work out why. Set aside about 90 minutes for the whole set, though you can do them in any order.
Nothing here is marked by a person. When you press Submit, the editor checks your code against the points listed under each task and tells you straight away what passed and what didn't (you need a free account to submit). If you get stuck, there are hints, and a worked solution once you've had a go. The first 2 tasks are free; the rest are part of the practice plan.
If it's been a while since you read the chapter, here is how it starts: “The double equals converts types before comparing; the triple equals does not.” .
1.Compare looselyexercise · easy · 10 min
Report whether a string and a number are loosely equal.
Passes when: #out should show loosely equal.
2.Compare strictlyexercise · easy · 10 min · practice plan
Report whether they are strictly equal.
Passes when: #out should show not strictly equal.
3.Check for null or undefinedexercise · easy · 10 min · practice plan
Use one check that catches both.
Passes when: #out should show nothing there.
4.Compare two objectsexercise · easy · 10 min · practice plan
Report whether two identical-looking objects are equal.
Passes when: #out should show different objects.
5.Convert then compareexercise · medium · 10 min · practice plan
Convert the text before comparing it strictly.
Passes when: #out should show matched.
6.Fix the loose comparisonbug fix · easy · 8 min
A string and a number should not be treated as equal.
Passes when: #out should show not strictly equal.
7.Fix the object compared by contentsbug fix · easy · 8 min · practice plan
Two objects are equal only if they are the same object.
Passes when: #out should show different objects.
8.Fix the strict null checkbug fix · easy · 8 min · practice plan
Strict equality misses undefined when checking for null.
Passes when: #out should show nothing there.
9.Fix the loose comparison against textbug fix · easy · 8 min · practice plan
The number should not be treated as equal to the string.
Passes when: #out should show no match.
10.Fix the empty string compared to zerobug fix · easy · 8 min · practice plan
Loose equality says they are equal, which is not wanted.
Passes when: #out should show not the same.
Between them these tasks cover Strict equality, Loose equality and Identity.
Looking for a different chapter? See every practice set, or switch to the interview theory questions.