JavaScript Getting Started learning the first JS Basics 1th/2 Page _ Basics

Source: Internet
Author: User
Tags lowercase
JavaScript learning the first JS Foundation

1, javascript Character set:
JavaScript uses the Unicode character set encoding.
Why do you use this code?
The reason is simple, 16-bit Unicode encoding can represent any written language of the Earth people. This is an important feature of language internationalization. (You may have seen a script written in Chinese, such as: function my functions () {});
Each character in JavaScript is represented in 2 bytes. (because it is 16-bit encoded)


2, Case sensitive:
JS is a case-sensitive language.
Note: I have made mistakes before.
HTML is case-insensitive. I often see someone write this,
<input type= "button" onclick= "A ()"/> (This is true)
If you put it in JS, you must use the onclick (lowercase Oh!). )
At the same time, only lowercase is used in XHTML.
This we do not need to be too concerned about, like this problem, in fact, can set themselves a standard, write their own program when all lowercase.
In addition, the semicolon is the same after each line of procedure, which we write.

3, Note:
Single:
Note 1
/* NOTE 2 * *
MultiRow
/* Note 3
* Note 3
* Note 3
*/

4, identifier:
An identifier is a name that is used to name variables and functions.
Rule: The first letter must be a letter, an underscore (_), or a dollar sign ($).
Why can't the first letter be numeric?
If the first for the number, JS very easy to treat it as a digital processing, then the name is meaningless, JS stipulated, it is easy to distinguish between the identifier and the number.

5, Direct quantity:
Is the data value that is displayed directly in the program.
For example: 1.2, "Hello", True, NULL, [1,2,3,4]
These are the direct quantities.

6, Reserved words and keywords:
What is specific, can go to google.cn.
In fact, as long as we do not take some special depressed names, will not conflict.

7, JS data type:
3 basic types; numbers, strings, and Boolean values.
2 kinds of small data types: null and undefined. (Why is it called a small data type?) Because they only define a value)
1 Compound types: object. (In this type, its value can be either a basic data type or a composite type, such as another object.)
Note: There is a special object----function in the object. (It is an object that can execute code.)

Some of the other objects:
Array:
Date class: Is the object of the date.
RegExp class: An object of a regular expression.
Error class: The object in JS where the errors occurred.

8, use the data type attention place:
1): Number:
Because of the number of 8 into the system, 10, 16 into the system ...
Octal: var num = 011; Start with "0"
hexadecimal: var num =0x1f; Start with "0x"
So for JS This can be recognized language, you must pay attention to.
Alert (377); 377
alert (0377); 255 = 3 * 64 + 7 * 8 + 7 * 1

There is an important object for arithmetic operations: math.
Specific can go to download the manual online, query the method inside.

2 Useful functions: isNaN () and Isfinite ()
isNaN (): is used to check whether its arguments are non-numeric values. Hint: Yes, no. (Not a number)
document.write (isNaN (0))//return False
document.write (isNaN (5-2))//return False
document.write (isNaN ("Hello"))//return True

The isfinite (number) function checks to see if its arguments are infinity.
Returns true if number is finite. Returns False if number is NaN (non-numeric) or infinity;

2): Character:
' Re right ';
In this way JS will mistakenly think that the end of the letter after you, causing errors.
So when it comes to this, escape must be used.
We can write this:
' You\ ' re right ';
In addition: You can search the escape sequence list google.com.

Simple operation Example of a string:
var a = "Cssrain";
var B = A.charat (a.length-1);  Intercepts the last character from the string A. Output: N
var c = a.substring (0, 2); Intercepts the 1th, 2 characters from the string A. Output: CS
var d = a.indexof (' s '); Finds the position of the first S occurrence from string a. Output: 1
As can be seen from the example, the cardinality starts from 0.
var e = a.substring (a.length-1); As you can see, the 2nd parameter of substring is not written,
The default is to the end.
var f = a.substring (a.length-1, a.length);//equivalent to

3): The conversion between numbers and characters:
Digit Turn character:
var number_to_string = number + ""; Method 1: Add an empty string.
var number_to_string =string (number); Method 2: Use the string () function.
var number_to_string =number. ToString (); Method 3: Use the ToString () function.
Note: the ToString () method is converted by default in 10.
If you want to use the 8 binary conversion, you can write this: number. ToString (8);

Character Spin number:
var string_to_number = string–0; Method 1: String minus 0.
var string_to_number = number (string); Method 2: Use the number () function.
var string_to_number = parseint (string); Method 3: Use the parseint () function.
String+0 can not be used in Method 1; This can result in string concatenation, not type conversions.
The number function conversion in Method 2 is very strict.
Like what:
var a = "19cssrain86";
var b = number (a); Output Nan.
If we use Method 3.
var C = parseint (a); Output 19
You can see that parseint () automatically ignores parts that are not digital.
parseint () takes only the integer part, ignoring the fractional part.
Parsefloat () will also take the decimal part of the division.
As with ToString (), parseint is also in the system, the default is 10.
If you want to use 8, you can write this: parseint ("077", 8); Output 63 = 7 * 8 + 7
When the character begins with 0, we must specify the second parameter, or JS may be converted to 8.

4): Boolean type:
Boolean in the digital environment: true converts to 1, false to 0.
In a character environment: true converts to True and false to false.
Boolean conversions:
var X_to_boolean = Boolean (x); Method 1: Use the Boolean () function.
var x_to_boolean =!x; Method 2: Use an exclamation mark.
Current 1/2 page 12 Next read the full text
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.