One, variable
JavaScript is a weakly typed scripting language that can be used without the need to define it (but to do the initial chemical work) before using a variable. "If you do not assign a value to a variable, the variable type is in an unknown state, and its corresponding type is" undefined ", which can be directly judged by the IF statement, which is true if the variable belongs to undefined, which represents false. 】
The main definition way:
1. Implicit definition--assigning values directly to variables;
2. Explicit definition--define variables using the var keyword.
Ii. Types of data
JavaScript is a weakly typed scripting language that does not need to specify a variable's data type when declaring a variable. JavaScript is dynamically determined at the time of interpretation, and data is stored in memory with data types, often as follows:
Numeric type number: contains integers and floating-point numbers;
Boolean type Boolean: Only True or false two value;
String type strings: strings must be enclosed in double or single quotation marks;
1. The specific type of the variable is determined by the assignment value
var num = 10;
Print type
Console.log (typeof num);
Undefined has no type. No value assigned
2. String splitting
var num= "Wo Men"
var result=num.split (""); split by Space
var num = "Hello, nice to see you"; var result = Num.split (""); for (var i=0;i<num.length;++i) { console.log (Result[i]) } // string Split Space
Point splitting
var num = "192.168.1.1"; var result = Num.split (".") ); for (var i=0;i<num.length;++i) { console.log (Result[i]) }// split with points
3. Comparison of strings
var stra = "Hello"; var strb = "Hello"; // true alert (Stra.indexof ("1")! =-1); // true
Application: 99 Multiplication table
Basic algorithms
for (var i = 0; I <= 9; i++) { for (var j = 1; J <= I; j + + ) { DOCUMENT.W Rite ( + "*" + j + "=" + I * j + "" ); } }
Form
<! DOCTYPE html>table{width:600px; //Table Height property can be set without setting, it is recommended not to setborder-collapse:separate; } table td{border:#0000001px solid; Text-align:center;//Center The contents of the <td> tag, and if the <th> tag, no line code can be automatically centered } </style>//The following sections are the core codedocument.write ("<table>");//<table></table> Add a table style to display the multiplication table for(varx = 1; x <= 9; X + +) {document.write ("<tr>");//<tr></tr> Tags for(vary = 1; Y <= x; y++) {document.write ("<td>" +y+ "x" +x+ "=" +y*x+ "</td>");//can also use <th> tags to play the role of the center of bold content } for(vary = 1; Y <= 9-x; y++) {document.write ("<td> </td>");//can also use <th> tags to play the role of the center of bold content} document.write ("</tr>"); } document.write ("</table>");</script></body>
JS basic syntax, defining variables-notes