JavaScript Common Sense

Source: Internet
Author: User

The difference between substring and substr

The substring () method is used to extract the character of a string intermediary between two specified subscripts.

Stringobject.substring (Start,stop)
Example:
<script type= "Text/javascript" >var str= "Hello world!" document.write ( str.substring(3,7) ) </script>
Results:
Lo W

The substr () method extracts a specified number of characters from the start subscript in a string.
Stringobject.substr (Start,length)
Example:
<script type= "Text/javascript" >var str= "Hello world!" document.write ( str.substr(3) ) </script>
Results:
Lo world!

--------------Split Line--------------------------

The difference between Getelementsbyname and getElementById

Document.getelementsbyname gets an array, and document.getElementById gets the unique element object, to get a particular element object through Document.getelementsbyname, and to add subscript: do Cument.getelementsbyname ("Text1") [0] Gets the first element object with the name value of Text1.

jquery in HTML (), text (), Val () difference

HTML is where you can add tags like <a></a>, <p></p>, etc.
Text can only be written if the above mark is written, it will be printed in text form.
Val is a property and only the object with that property can call

The return in JS; return False;return true;

Retrun true; Returns the correct processing result.

return false; Branch error processing result, terminate processing.

return; Returns control to the page.

See an example:

<script type= "Text/javascript" >
function A () {
if (true)
return false;
}
Function B () {
Console.log ('-----------');
}
function Test () {
A ();
b ();
}
Test ();
</script>

The result of this example is:

-----------

Call the A () function in the test () function, where return false is equivalent to the return value for the test () function. The test () function cannot be prevented from executing.

If you change to:

<script type= "Text/javascript" >
function A () {
if (true)
return false;
}
Function B () {
Console.log ('-----------');
}
function Test () {
return a ();
b ();
}
Test ();
</script>

The result is:

Empty

Return a () here, which prevents the program from running.

It's good to use this example to understand Retun.

Above is a number of basic JS knowledge, is also the daily common knowledge, and very easy to mistake, so write down, from time to read.



JavaScript Common Sense

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.