A On the three-tier web front end:
Structure-level HTML describes the structure of a page from a semantic perspective
Style layer CSS from an aesthetic perspective, beautify the page
Behavioral layer JavaScript enhances user experience from an interactive perspective
Ii. recognition of numbers and strings-direct volume
alert (886); 886 is a number, so no quotes are required
Strings are words that people say, such as words and sentences, which are not numbers. Be sure to enclose the quotation marks.
Alert (The weather is fine today); // the wrong statement, because there is no quotation mark |
Three, several output modes
1 console.log ("nice weather Today"); |
Console represents "Consoles", log is "output"
2.alert (); Warning Window Popup
Four Variable
in a computer program, there is the same amount, that is, the letters to represent numbers, strings and other things, called "variables."
Variable names have a naming convention:
only by English letters, numbers, underscores, dollar sign $ and cannot start with a number, and cannot be JavaScript reserved words .
The following words, called reserved words, are not allowed as variable names, do not remember:
Abstract, Boolean, Byte, Char, class, const, debugger, double, enum, export, extends, final, float, goto
Implements, import, int, interface, long, native, package, private, protected, public, short, static, super, synchronized, Throws, transient, volatile
Uppercase letters are available and case sensitive. In other words, a and a are two variables.
1 var A = 250; 2 var a = 888; |
In JavaScript, variables are always defined with Var, and C, Java, and so on are different.
01. Distinguishing between variables and strings
var a = 100;
Console.log ("Man, what's the first letter in the alphabet?") ");
Console.log ("a"); Output Letter A
This A is inside the quotation marks, so it's a string "a" instead of a variable. In other words, a variable cannot be quoted if it wants to output the saved content.
02. Variable type
var a = 100; A variable A is defined and assigned a value of 100
Console.log (typeof a); Type of output a variable
typeof means "type of XXX"
Grammar:
JavaScript, as long as the number, then the numerical type, regardless of the whole float, regardless of size, whether positive or negative, is the
03. String Type
1 var a = "abcde";
2 var b = " self-study ";
3 var c = "123123";
4 var d = " hahaha haha ";
5 var e = ""; // empty string
04 Hyphenation Fuhai No.
On the keyboard + in JS There are two layers of meaning:
1) Hyphen
2) Add
Console.log (" i " + " love " + "you "); Hyphen, put three separate characters, connected together
Console.log (" i + love + you "); Output AS-is
Console.log (1+2+3); Output 6
It is also a plus sign, sometimes a hyphen, sometimes a plus sign. When is a hyphen? When is it added?
If both of the plus signs are numeric, this is the plus. Otherwise, it is a hyphen.
1 <script type= "Text/javascript" >
var a = "1";
var B = 2; Output 12
Console.log (A + B);
</script>
var a = 234234;
var B = 234323112;
Console.log ("A+b"); Because the quotation marks are added, the output is//ab
var a = 1;
var B = 2;
Console.log ("a" + B); "A" is not a variable! So that's "a" +2 output A2
var a = 123;
var B = "123";
Console.log (A + "B"); Output 123b
Five Transfer of variable values
Assigns the value to the right of the equal sign to the left variable, the variable to the right of the equal sign, and the value unchanged.
put B the value assigned to a , b not change.
Six Operators and expressions
+ |
Add |
- |
Reducing |
* |
By |
/ |
Except (question mark Bar) |
% |
Take the remainder |
( ) |
Brackets |
01, exponentiation and open radical
= 3 * 3 * 3 * 3
var a = Math.pow (3,4); Console.log (a); |
The POW is what power means.
var a = Math.pow (3,4*5); Console.log (a); |
Open root:
var a = math.sqrt (bayi); Console.log (a); |
SQRT is the meaning of "open root" in English.
Seven Variable format conversions
User's input
var a=prompt ("Please enter what you want to say");
Console.log (a);
Prompt is specifically used to eject the user Input dialog box user regardless of input, is a string!
01 string → Number
Method: parseint ("5") output is the number 5
Parse is the meaning of the conversion in English, int represents an integer. Note the spelling:
parseint
02.parseInt with auto-purifying function
Console.log (parseint ("365 Day Love you 10000 times")); Output 365, only the numbers that begin are retained
03 Auto with truncation decimal function (rounding, not rounding)
Console.log (parseint (5.8)); Output 5
Eight Boolean and relational operators, logical operators
A Boolean value of two, true, false.
01. Relational Operators
- > Greater than sign
- < less sign
- >= greater than or equal to
- <= less than or equal to
- = = equals
- = = = All equals
- ! = does not equal
- !== Not all equal to
relational operators, the result is a Boolean value, which means that the resulting thing is either true , or False
Note that in JS the = symbol has only one meaning! It means assignment!!
If you want to determine whether two things are equal, you need to use the symbol = =
= = etc is not rigorous, will be different types of things to the same type to compare:
Console.log ("5" = = 5); True Console.log (56 = = "56"); True |
All Equals, is three equals = = =
1//Full equals 2 Console.log ("56" = = = 56); False 3 Console.log (56 = = = "56"); False 4 Console.log ("56" = = = = "56"); True 5 Console.log (56 = = 56); True |
In other words, = = two equals, not rigorous, "5" and 5 is true; = = three equals more rigorous, "5" and 5 are false
02. Logical Operators
There are three logical operators:
&& and (and)
|| Or
! Non -
Those that participate in logical operations are Boolean values. That is, only true, false to participate in the logical operation, the resulting answer, is still a Boolean value.
&& says "and" means it's true. Console.log (True && true); True Console.log (True && false); False Console.log (False && true); False Console.log (False && false); False |
Nine functions
function, which is an encapsulation. is to encapsulate some of the statements into the function. These statements are executed in the form of a call.
The use of functions is two steps, the first step, the definition of a function :
Grammar:
The second step, the function of the call.
JavaScript Preliminary understanding