A preliminary understanding of JavaScript

Source: Internet
Author: User
Tags string methods

grasp oneself, is always have a clear heart, have a clear feelings. Hey, We in 2014-2015 of the span, we rest for four days, today back to the learning stage, knocking up the keyboard suddenly a little strange, think of time really good fast, here we have been over the rhythm of two months, here to learn the basic knowledge of C #, SQL Server statements and HTML,CSS, and so on, the progress of learning can keep up with the rhythm, but the grasp of the situation is still need to review, so it is necessary to arrange their own, today we have a preliminary understanding of JavaScript, the following to summarize JavaScript.

I. The composition of JavaScript

JavaScript is made up of three parts, namely:

1:ecmascript

2:bom (Document Object model)

3:dom (Browser object model)

Two. Variables

declaring a variable using only a keyword var;

        var123;         var " 456 " ;         var v = function () {            alert ("helloWorld");        }

The following keyword is used to show the type of the variable:

       varA =123; varb ="456"; varv =function () {alert ("Hello World"); }        //Window.alert (a); //Show variables in window//Window.alert (typeof a); //print out the type of variable B//Window.alert (typeof b);Window.alert (typeofV);//Print out function, for method//Window.alert (v); //Print out 1 methods of body

There are six possible types of return values for the TypeOf operator: number, String, Boolean (Boolean), object, method, and undefined (undefined).

three. Use of some of these methods

1. The following is a simple way to describe the string type of data:

<script>//use of String methods    varA ="ABCDEFG"; varb ="HIJKLMN" ;             Window.alert (a.length); //the length of the string    varArray = A.split (' ');//when there is a space event between the strings, you can choose to split the space between the strings, and then divide the string by "     for(vari =0; i < Array.Length; i++) {alert (array[i]); } alert (A.substring (2,4));//intercepts several characters. Where to start?alert (A.charat (2));//gets a single string in which the index of a character is passed inside the methodalert (A.charcodeat (2));//gets the position of the character in the Asii codealert (A.concat (b))//Connect two stringsAlert"Jokes". Concat (a)) alert (A.indexof ("D"))//gets the index of the characterAlert (A.lastindexof ("D"))//gets the index of the character from the following numberalert (A.replace ("ABC","CBA"));//Replace stringalert (B.trim ()); //remove spaces at both ends of a stringalert (b); </script>

See the above method is still very familiar with, a lot of methods used in C # is also using these same name method to find a value, here we in front if the blood can also be in the type of variable here can be used as a review to learn, hey.

2.boolean type of simple learning

<script>//Boolean type    varf =false; varv ="ABC"; if(v) {//You can put V in here directly, true if the string is not empty, or False if the string is emptyalert (v); }    Else{alert ("an empty string")    }    varv =""; if(v) {alert (v); }    Else{alert ("an empty string")    }    </script>

in this use of the Boolea type time, it should be noted that: and we have learned in C # is different, our if statement can use the string type in the judgment statement, if we define the variable is not an empty string, then can return true, that is, output its value When we define the variable space-time string, then return true to let it pop up as an empty string in the prompt box.

3.Number type

<script>//Number Type    varA ="123"; varb =456; varc =789.00; Alert (A+ b);//in JS, when any type is added to a string type, it is converted to a string typeAlert (b+parseint (a));//here to convert string A to reshapeAlert (b+ parsefloat (a))//convert C to float typeAlert (b+ Number (a));//in this case, the number class is used to define the numeric type, so it is convertedalert (Number.MAX_VALUE); //The maximum value that can be stored in JSAlert (Number.min_value)//The minimum value that can be stored in JS</script>

in JavaScript, any type and string type that you want to add will be converted to a string type and then concatenated with its string. If you want to cross an int type, you can use the method parseint conversion.

Four. Defining Methods

The definition method must begin with the keyword function and then write the method name of the method to be defined:

<script>function Sayhi (A, b) {//define method, must start with functionAlert (A +b); } sayhi (1,2); function Say () {//method used to demonstrate the use of argumentsAlert (arguments[0] + arguments[1] + arguments[2]); Alert ("OK"); } Say (1,2,3); </script>

in JavaScript, arguments is a special property of an object. The arguments object is like an array, but it is not an array.

1:arguments is a copy of the actual parameter received, in the lexical analysis, first by the formal parameters of the AO attribute, the value of undefined, when the argument came, then modify the corresponding properties of AO;
2: Collect all the received arguments, put into a arguments object, T (a,b,c) {}, call: T (1,2,3,4,5) 5 parameters, at this time, the AO attribute only a,b,c,3 properties, arguments there 1,2,3,4,5, all The value. property: Length, gets the arguments of the object, callee, references the function that is currently executing. Well, today's study is here, we are only a preliminary understanding of JavaScript, is said to be quite difficult to learn, hey, to study hard, in MSDN See JavaScript Foundation is understandable, but I think a language is not so simple, So at the beginning of the 2015 new, to have a new impetus, will be more efforts.

A preliminary understanding of JavaScript

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.