Data Types in JavaScript BASICS (1)

Source: Internet
Author: User

Basics
Javascript: 1. Data Type and Value
1. javascript: three basic types of data are allowed: Numbers, strings, and boolean values. In addition, two types of small data are supported: null and undefine ).
2. javascript: it also supports conforming data types-objects. Objects in javascript are divided into two types. One is an unordered set of named values represented by an object, an ordered set of numbered values. In fact, an ordered set is an Array ).
3. javascript: it also defines another special object-function, and some specialized objects defined by javascript (similar to the class encapsulated by C)
 
View Code
1 <script>
2 integer values: 3 or 10000. To put it bluntly, it is a number.
3. Float direct traffic: 3.14, 2345.567, and so on, that is, with a decimal point
4. String quantity: "3.14", "demo", and so on. The so-called string is a Unicode Character Sequence enclosed by single quotation marks or double quotation marks.
5
6 convert the number to a string: 1, var s = 100; s + = "What you name"; the number is first
7. convert to a string
8 2, var s = 100 + "; add an empty string
9 3. You can use the String () function or
10 use the toString function.
11. convert a string to a number: var product = "2" * "2". In fact, when a string is used for a digital ring
In the 12th environment, it is automatically converted into a number. You can also reduce the value by 0 to achieve the same effect, or use
13 Number () function
14 Boolean value:
15 here I would like to share with you the following content: there will be more use in the future. 1. When a Boolean value is used in a numeric environment, true is converted to 1, and false is converted to 0. In a string environment, true is converted to true, if the value is false, the string is converted to false.
16 functions:
17. The function is an executable JavaScript code segment. Here, the function can be used as a data type or as a property assigned to an object like other types. When a value is assigned successfully, the attribute is often used as a reference to a method. Commonly used.
18 function quantity: var square = function (x) {return x * x}; // It is often used later. You must understand or remember it.
19 </script>

Javascript: 2. Objects
1. Object
View Code
1 <script>
2 var o = new Object (); // javascript is case sensitive!
3 var now = new Date ()
4 var regex = new RegExp ("^ \ +? \ D {1} \ d {3} $ ") // Regular Expression
5. Direct Volume of objects:
6 var point = {x: 12, y: 34 };
7 var point2 = {"super": {day: Sunday, day1: Monday }}// the property of the object references another object.
8. Object conversion:
9 when a non-empty object is used in a Boolean environment: it is converted to true. When used in a string environment, javascript calls the toString () method of the object, and the value returned by this function. When used in a digital environment, javascript will call the valueOf () method of this object. If the returned value is of a basic type, this value will be used, in most cases, the object itself is returned. In this case, javascript calls the toString () method back to convert the object into a string and then tries to convert it to a number. I hope you will understand the above concepts and will use them later.
10 </script>

2. Array
<Script>
Var array = new Array ();
Var arr = new Array (1.2, "Javascript", {x: 12, y: 23 }) //
Direct array quantity:
Var a = [1.2, "Javascript", {x: 12, y: 23}] // The array is the [] number, and the object is the {} number. It is easy to remember!
</Script>
3. Null (Null)
The javascript keyword Null is a special value, which indicates that there is no value. null is often seen as a special value of the object type, that is, representing the value of no object. When the value of a Variable
If it is null, it indicates that its value is not valid (Array, Object, number, String, Boolean value). Details: null is converted to false in a Boolean environment;
Change the environment to 0.
4. Undefined (Undefined)
When a declared variable is used but no value is assigned, or a non-existing object attribute is used
That is, the undefined value. In the future (namespace, the module is still used quite a lot, you need to understand), details: underfined converts it to false in a Boolean environment, in a digital environment
It is converted to NaN. This is different from null. The object that encapsulates it is Error.
Summary: although I can understand the above content at a glance, I hope you will be a beginner like me. Do not care!

 
From ben2012
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.