Dynamic - because of what you see on paper when you analyze the code, is most likely not what you’re going to get when the program runs.
In contrast, static languages will not compile into runnable code unless all values (or value types) are known upfront.
var thisIsAString = 'I am a string';
thisIsAString = 1; // assign an integer to thisIsAString
console.log(thisIsAString); // logs 1 to the console
The variable ‘thisIsAString’ began its life as a string,
but then I switched it to an integer.
If you pull up the console on your browser
(hitting F12 should do it in most browers),
you’ll notice that the code runs just fine
even though I changed the variable’s type during program execution.
This behavior comes with both benefits and drawbacks, so I would encourage you to keep learning more about programming languages in order to understand the differences!
Top comments (0)