Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>strong/weak</strong> <em>can</em> be thought of in relation to how the compiler, if applicable, handles typing.</p> <ul> <li><p><a href="http://en.wikipedia.org/wiki/Programming_language#Weak_and_strong_typing" rel="noreferrer"><strong>Weakly typed</strong></a> means the compiler, if applicable, doesn't enforce correct typing. Without implicit compiler interjection, the instruction will error during run-time.</p> <pre><code>"12345" * 1 === 12345 // string * number =&gt; number </code></pre> <p><strong><em>Strongly typed</em></strong> means there is a compiler, and it wants you an explicit cast from <em>string</em> to <em>integer</em>.</p> <pre><code>(int) "12345" * 1 === 12345 </code></pre> <p>In either case, some compiler's features can implicitly alter the instruction during compile-time to do conversions for you, if it can determine that is the right thing to do.</p> <p>Thus far, JavaScript can be categorized as Not-Strongly-Typed. That either means it's weakly-typed or un-typed.</p></li> </ul> <p><strong>dynamic/static</strong> <em>can</em> be thought of in relation to how the language instructions manipulate types.</p> <ul> <li><p><a href="http://en.wikipedia.org/wiki/Programming_language#Static_versus_dynamic_typing" rel="noreferrer"><strong>Dynamically typed</strong></a> means the <strong>value</strong>'s type is enforced, but the variable simply represents any value of any type.</p> <pre><code>x = 12345; // number x = "string"; // string x = { key: "value" }; // object y = 123 + x; // error or implicit conversion must take place. </code></pre> <p><strong><em>Statically typed</em></strong> means the <strong>variable</strong> type is strongly enforced, and the value type is less-so enforced.</p> <pre><code>int x = 12345; // binds x to the type int x = "string"; // too late, x is an integer - error string y = 123; // error or implicit conversion must take place. </code></pre> <p>Thus far, JavaScript can be categorized as Not-Statically-Typed. Also, it appears to be Dynamically Typed, if typed at all. So we need to see what Typing means.</p></li> </ul> <p><a href="http://en.wikipedia.org/wiki/Programming_language#Typed_versus_untyped_languages" rel="noreferrer"><strong>Typed</strong></a> means that the language distinguishes between different types such as <em>string</em>, <em>number</em>, <em>boolean</em>, <em>object</em>, <em>array</em>, <em>null</em>, <em>undefined</em> and so on. Also each operation is bound to specific types. So you cannot divide an <em>integer</em> by a <em>string</em>.</p> <pre><code> 2 / "blah" // produces NaN </code></pre> <p><strong><em>Untyped</em></strong> means the operation of dividing <em>integer</em> by <em>string</em> would result in treating the first four bytes of <em>string</em> as <em>integer</em>. This is because Untyped operations take place directly on bits, there are no types to observe. The outcome will be something quite unexpected:</p> <pre><code> 2 / "blah" // will be treated as 2 / 1500275048 </code></pre> <p>Since JavaScript behaves according to the definition of being Typed, it must be. And therefore it must be Dynamically Typed, and Weakly Typed.</p> <p>If anybody claims JavaScript is Untyped, it is merely for academic theory, not for practical application.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload