We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Dynamic and Weak

Like Python, Ruby, and PHP, JavaScript is a dynamically-typed (not statically-typed) language. Its variable types are only known at runtime (yes, yes, we'll talk about TypeScript in another course). Some of us like being able to see the types of our variables in our editors, okay?

Now, unlike Python, it's also weakly-typed, meaning it will automatically convert types when you do things like add a number to a string. This can lead to some unexpected behavior if you're not careful...

let answerToLife = 42;
let answerToTheUniverse = "42";

// obviously JavaScript thinks that adding strings
// and numbers is totally sane and normal behavior
const answerToEverything = answerToLife + answerToTheUniverse;

console.log(answerToEverything);
// "4242"

Assignment

Run the code in its current state... Notice the very odd sum?

Well, someone introduced a bug causing Textio's message totals to be incorrect. Fix the error in the code by ensuring the value matches the correct type as you'd expect.