Let's start out with an example to show how loosely typed languages behave:
// Code 1.1// Declare a variable and assign a valuevar x = "Hello";// Down the line// you might have forgotten // about the original value of x////// Re-assign the valuex = 1;// Log valueconsole.log(x); // 1
The variable x was initially declared and assigned a string value, Hello. The same x got re-assigned to a numeric value, 1. Nothing went wrong; the code was interpreted and when we logged the value to the console, it logged the latest value of x, which is 1.
This is not just a string-number thing; the same thing applies to every other type, including complex data structures:
// Code 1.2var isCompleted;// Assign nullisCompleted = null; ...