HTML and CSS Reference
In-Depth Information
while !! provides a double negative, and therefore prints out the Boolean value
of any value:
!!""
false
!!"hello"
true
Dynamic Typing
Finally, it is worth reiterating that JavaScript is a dynamically typed language.
Languages such as Java and C++ are statically typed languages. In statically typed lan-
guages, all variables are assigned a type at compile time, and this type cannot be changed.
//
The terms strong and weak typing are sometimes used to refer to statically typed
and dynamically typed languages respectively.
In a statically typed language, the compiler can perform type checking: if a variable is
defined to store an integer, the compiler can check that it is not assigned a string. This
catches many causes of bugs before they can become an issue at run-time.
As we have seen, JavaScript variables derive their types based on the values they are as-
signed at run-time, and variables can change their type if they are assigned a new value.
As a result it is not possible to perform static type checking in JavaScript, e.g. to ensure a
string is not provided where a number is expected.
Consider the following function that adds two numbers together:
function add(v1, v2) {
return v1+v2;
 
Search WWH ::




Custom Search