JavaScript learning log (1)

Source: Internet
Author: User

JavaScript usage:
1, the script in the HTML must be between <script> and </script> tags, can be placed in the HTML page <body> and 2, you can also put the script in the external. js file, you need to use, in the <script> tag's "src" attribute to set the reference path. External scripts cannot contain <script> tags.
JavaScript output:
1, use Window.alert () pop-up warning box;
2. Use the document.write () method to write the contents to the HTML document;
3, write to HTML element using innerHTML;
4. Use Console.log () to write to the browser's console.
Note: Use document.write () to write only to the document output. If document.write is executed after the document has finished loading, the entire HTML page will be overwritten.
Use the Console.log () method to display JavaScript values in the browser. F12 Enable debug mode, click the "Console" menu in the Debug window.
JS Section:<script>
function ReWrite () {
document.write (' This page is rewritten ');
Console.log (' console ');
Console.log (' abc ');
}
</script>
HTML section: <input type= "button" value= "Rewrite page" onclick= "ReWrite ()"/>
After running the original HTML page is overwritten, the Debug Window "console" menu can see the output.
To declare (create) a JavaScript variable:
Declaring variables using the var keyword, it is recommended to declare the required variables uniformly at the beginning of the code.
Value=undefined: The value of the variable carname is undefined when the Var carname is executed and the Carname variable is not initialized.
When you re-declare a JavaScript variable, the value of the variable is not lost.
var carname= ' BWM ';
var carname;
The value of Carname is still ' BWM '.
the Let variable in JS:
Let allows you to declare a variable, statement, or expression that has a scope that is limited to the block level. A let declaration's variable is only available in its declared block or sub-block, which is similar to Var. The main difference between the two is that the variable declared by Var is scoped to the entire enclosing function.
function Letvartest () {
var a= "abc";
{
var A= "000";
alert (a); 000
}
alert (a); 000
Let b= "AAA";
{
Let b= "SSS";
alert (b); Sss
}
alert (b); Aaa
}

JavaScript Learning log (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.