Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 118797 of Values

  • Revision slug: JavaScript/Guide/Obsolete_Pages/Values
  • Revision title: Values
  • Revision id: 118797
  • Created:
  • Creator: user01
  • Is current revision? No
  • Comment Added obsolete and merged note; 14 words added

Revision Content

Note: This page is obsolete and has been merged into Core Language Features

Introduction

JavaScript recognizes the following types of values:

  • Numbers, such as 42 or 3.14159
  • Logical (Boolean) values, either true or false
  • Strings, such as "Howdy!"
  • null, a special keyword denoting a null value; null is also a primitive value. Because JavaScript is case-sensitive, null is not the same as Null, NULL, or any other variant
  • undefined, a top-level property whose value is undefined; undefined is also a primitive value.

This relatively small set of types of values, or data types, enables you to perform useful functions with your applications. There is no explicit distinction between integer and real-valued numbers. Nor is there an explicit date data type in JavaScript. However, you can use the Date object and its methods to handle dates. Objects and functions are the other fundamental elements in the language. You can think of objects as named containers for values, and functions as procedures that your application can perform.

Data Type Conversion

JavaScript is a dynamically typed language. That means you do not have to specify the data type of a variable when you declare it, and data types are converted automatically as needed during script execution. So, for example, you could define a variable as follows:

var answer = 42;

And later, you could assign the same variable a string value, for example:

 

answer = "Thanks for all the fish...";

 

Because JavaScript is dynamically typed, this assignment does not cause an error message.

In expressions involving numeric and string values with the + operator, JavaScript converts numeric values to strings. For example, consider the following statements:

x = "The answer is " + 42 // returns "The answer is 42"
y = 42 + " is the answer" // returns "42 is the answer"

In statements involving other operators, JavaScript does not convert numeric values to strings. For example:

"37" - 7 // returns 30
"37" + 7 // returns "377"

{{ PreviousNext("Core_JavaScript_1.5_Guide:JavaScript_Overview", "Core_JavaScript_1.5_Guide:Variables") }}

{{ languages( { "zh-tw": "zh_tw/Core_JavaScript_1.5_教學/值", "es": "es/Gu\u00eda_JavaScript_1.5/Valores", "fr": "fr/Guide_JavaScript_1.5/Valeurs", "ja": "ja/Core_JavaScript_1.5_Guide/Values", "ko": "ko/Core_JavaScript_1.5_Guide/Values", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Warto\u015bci", "zh-cn": "cn/Core_JavaScript_1.5_Guide/Values" } ) }}

Revision Source

<div class="note"><strong>Note:</strong> This page is obsolete and has been merged into <a href="/en/Core_JavaScript_1.5_Guide/Core_Language_Features#Values" title="en/Core JavaScript 1.5 Guide/Core Language Features#Values">Core Language Features</a></div>
<h2>Introduction</h2>
<p>JavaScript recognizes the following types of values:</p>
<ul> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Number" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Number">Numbers</a>, such as 42 or 3.14159</li> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Boolean">Logical (Boolean)</a> values, either <code>true</code> or <code>false</code></li> <li><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/String" title="en/Core_JavaScript_1.5_Reference/Global_Objects/String">Strings</a>, such as "Howdy!"</li> <li><code>null</code>, a special keyword denoting a null value; <code>null</code> is also a primitive value. Because JavaScript is case-sensitive, <code>null</code> is not the same as <code>Null</code>, <code>NULL</code>, or any other variant</li> <li><code><a href="/en/Core_JavaScript_1.5_Reference/Global_Properties/undefined" title="en/Core_JavaScript_1.5_Reference/Global_Properties/undefined">undefined</a></code>, a top-level property whose value is undefined; <code>undefined</code> is also a primitive value.</li>
</ul>
<p>This relatively small set of types of values, or <em>data types</em>, enables you to perform useful functions with your applications. There is no explicit distinction between integer and real-valued numbers. Nor is there an explicit date data type in JavaScript. However, you can use the <code><a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Date" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Date">Date</a></code> object and its methods to handle dates. <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Object" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Object">Objects</a> and <a href="/en/Core_JavaScript_1.5_Reference/Global_Objects/Function" title="en/Core_JavaScript_1.5_Reference/Global_Objects/Function">functions</a> are the other fundamental elements in the language. You can think of objects as named containers for values, and functions as procedures that your application can perform.</p>
<h2>Data Type Conversion</h2>
<p>JavaScript is a dynamically typed language. That means you do not have to specify the data type of a variable when you declare it, and data types are converted automatically as needed during script execution. So, for example, you could define a variable as follows:</p>
<pre class="brush: js">var answer = 42;
</pre>
<p>And later, you could assign the same variable a string value, for example:</p>
<p> </p>
<pre>answer = "Thanks for all the fish...";
</pre>
<p> </p>
<p>Because JavaScript is dynamically typed, this assignment does not cause an error message.</p>
<p>In expressions involving numeric and string values with the + operator, JavaScript converts numeric values to strings. For example, consider the following statements:</p>
<pre class="eval">x = "The answer is " + 42 // returns "The answer is 42"
y = 42 + " is the answer" // returns "42 is the answer"
</pre>
<p>In statements involving other operators, JavaScript does not convert numeric values to strings. For example:</p>
<pre class="eval">"37" - 7 // returns 30
"37" + 7 // returns "377"
</pre>
<p>{{ PreviousNext("Core_JavaScript_1.5_Guide:JavaScript_Overview", "Core_JavaScript_1.5_Guide:Variables") }}</p>
<p>{{ languages( { "zh-tw": "zh_tw/Core_JavaScript_1.5_教學/值", "es": "es/Gu\u00eda_JavaScript_1.5/Valores", "fr": "fr/Guide_JavaScript_1.5/Valeurs", "ja": "ja/Core_JavaScript_1.5_Guide/Values", "ko": "ko/Core_JavaScript_1.5_Guide/Values", "pl": "pl/Przewodnik_po_j\u0119zyku_JavaScript_1.5/Warto\u015bci", "zh-cn": "cn/Core_JavaScript_1.5_Guide/Values" } ) }}</p>
Revert to this revision