Is JavaScript dynamically typed?
Written by Jatin Thacker, Automation Architect · Updated
This answer is one piece of Chapter 1: Values and Variables.
MDN puts it plainly: JavaScript is a dynamic language with dynamic types. Nothing stops you assigning a string to a variable that held a number, and typeof reports the type of the value at that moment.
For a tester this matters in two places. A value read from the page, such as textContent, is always a string, even when it looks like a number, so '7' === 7 is false. And a typo that assigns the wrong kind of value fails at run time, not before, which is one reason teams later move test code to TypeScript.
let value = 42;
console.log(typeof value);
value = 'forty-two';
console.log(typeof value);number string
const count = await badge.textContent(), which holds '5'. What happens when you check count === 5?Related questions
AI can write the test now. The job is knowing whether it checks anything. That's what the course teaches, one chapter at a time.
163 lessons · 226 drills · start free