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)