How JavaScript is introduced
{#1 write directly #} <script> alert (' Hello Yuan ') </script>{#2 import File #} <script Src= "Hello.js" ></script>
2.1 Variables
1 You do not declare variable types when declaring variables. All use the var keyword;
var A;
2 A row can declare multiple variables. And can be of different types.
var name= "Yuan", age=20, job= "lecturer";
3 (understand) You can declare variables without var. if you don't use Var then it is a global variable.
4 variable name, first character can only be letter, underscore, $ dollar symbol three select one, and case-sensitive, x and X are two variables
5 variables should also adhere to one of the following well-known naming conventions:
The first letter of the Camel notation is lowercase, and the next letters begin with uppercase characters. For example:var mytestvalue = 0, Mysecondvalue = "Hi" = 0, Mysecondvalue = "Hi" = 0, SMYSECONDV alue = "HI";
Attention:
function func1 () { var a = 123; b=456 } func1 (); // alert (a); // alert (b); // Not recommended
1 the end of each line can be without a semicolon. No semicolon will end with a newline character as each line
a=1;b=2; a=1 b=2;------ Error A=1b=2// recommended a=1; b=2; {a=1 ; b=2; // recommended Add tab A=1; b=2;}
View Code
2 Comments Support multiline comments and single-line comments./* */ /
3 using {} to encapsulate a block of code
2.3 Constants and identifiers
Constants : data values that appear directly in the program
identifiers :
- Consists of letters, numbers, underscores (_), Dollar signs ($) that do not begin with a number
- a name commonly used to denote functions, variables, etc.
- For example: _ABC, $ABC, abc,abc123 is an identifier, and 1ABC is not
- Words that represent a particular meaning in the JavaScript language are called reserved words and do not allow programs to be redefined as identifiers
Basic learning of JavaScript (i)