JavaScript Learning Note 1

Source: Internet
Author: User

Output statement

<script type= "Text/javascript" >

Alert ("<SCR" + "ipt>");

</script>

Grammatical composition

    1. Case sensitive;
    2. The first character must be a letter, an underscore, or a dollar sign ($)
    3. You cannot use keywords, reserved words, true, false, and NULL as identifiers.
    4. Variables are loosely typed (any type).
    5. Define variables with the var operator for example: Var box;

Data type

Learning Essentials:

1. The TypeOf operator------------function: detects the type of variable, and can also detect function and object is necessary.

<script type= "Text/javascript" >  var box= ' Li ';  Alert (typeof box);  Alert (typeof ') </script>  --------------------------------------------------------results: String

2. Undefined type--------------Assign values when no assignment is defined


3. Null type--------------only one worth data type, special value NULL, NULL object reference (pointer) typeof operator detection Null returns object

<script type= "Text/javascript" >
var Box1=null;alert (typeof Box1); alert (typeof null); var Box;var car = null;alert (typeof box = = typeof car) </script>
-------------------------------------------------------
Result:object object true

4. Boolean type--------two values false and True
To convert a value to its corresponding Boolean value, you can use the transform function, Boolean (). var hello = ' Hello world! '; var Hello2 = Boolean (hello); alert (typeof hello); above is a display transformation, which is a mandatory conversion. In practical applications, there is also an implicit conversion. For example, there is an implicit conversion in the conditional judgment within the IF condition statement. var hello = ' Hello world! '; if (hello) {alert (' If the condition is true, execute my this one! ‘);} else {alert (' If the condition is false, execute me! ‘);

5. Number type-----------integers and floating-point numbers

Alert (parseint (' 456Lee ')); 456 returning an integral number of parts

Alert (parsefloat (' 0123.400Lee ')); 123.4 returning floating-point numbers


6. String Type

The ToString () method generally does not need to pass arguments, but it can be passed into a string when the value is converted to a literal.
var box = 10;
Alert (box.tostring ()); 10, default output
Alert (box.tostring (2)); 1010, binary output
Alert (box.tostring (8)); 12, octal output
Alert (box.tostring (10)); 10, decimal output
Alert (box.tostring (16)); A, hexadecimal output

PS: If the value has the ToString () method, the method is called and the corresponding result is returned, or "null" or "undeinfed" if it is null or undefined.


7. Type of Object

The object in ECMAScript is actually a set of data and functions. An object can be created by executing the new operator followed by the name of the object type to be created.
var box = new Object ();

JavaScript Learning Note 1

Related Article

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.