当前位置:网站首页>Start learning simple JS

Start learning simple JS

2022-06-23 22:27:00 Mike_ JioDan

1. know JS

js Concept : Run in browser ( client ) The explanation of ( Line by line ) Scripting language .

js engine : perform js Code : Execute line by line from top to bottom , Terminate if problems occur .

js The role of :

Html: structure , skeleton 
css: performance , beautify 
js: Behavior   Dynamic effect ( Shuffling figure .tab Switch . floor . Drag and drop , Baidu search , Form validation )

js At the heart of :

<ECMA: standard JS grammar >

<w3c: standard html and css>

1.ECAM-Script: Formulated the js Grammatical norms of

2.BOM: (browser object model) Browser object model , It provides a set of tools to operate the browser API Such as : Open and close the browser window , Forward go1 back off (go-1)

3.dom:(docuement object madel) Document object model , Provides a set of operation pages (body What's in it API.

 In short ,BOM And DOM It's all through JS  To operate the page .

2.JS Basic grammar of

2.1.js Code writing

1. Inline 
	a Labeled <a href="javascript:js Code ;"> Baidu </a>
	 Not a Labeled ,<button  Behavior properties ="js Code "> Button </button>
	 Events are required to trigger , Such as onclick, Trigger... When clicked .
2. embedded 
	 The way of writing :<script></script>
	 Writing position : You can write anywhere JS Code ( It is not recommended to write at the top , Because it is loaded from top to bottom , So it is recommended to write at the bottom , There can be multiple pairs of labels , Load in sequence , No coverage )
3. Outer chain 
	 The way of writing :<script src="demo.js"></script>
	 Be careful :1. In the introduction of the outer chain , Styles within labels are ignored .
				2.demo.js Direct writing js Code .

2.2JS Notes

	 notes : Multi line comments and single line comments 
	 effect : Explanation of the code 
	 Single-line comments : Multiline comment 

2.3js Variable

Variable : A container for storing data in a program !

	 How to define variables 
	a) The most common way :
		var x = 20000; Declare a variable , At the same time x assignment 20000
		var  For declaring variables ( Tell the computer ,x It's a new variable )
	b) The other way 
		var x; Declare a variable 
		x=20; Assignment after declaration 
		var a,b,c; Declare multiple variables 
		a=20;
		b=20:
		 Declare multiple variables and assign values .
		var a=20,b,v; You can also add an assignment to the declaration 

2.4 Output syntax of variables

		alert( Content )
		 effect : Pop up content 
		console.log( Content )
		 effect : Output content in the console 
		document.write( Content )
		 effect : Output in the page 

2.5JS Naming rules and specifications for

		 The rules :
		1. Part of the : Numbers 、 Letter 、 Underline 、¥
		2. Do not start with a number 
		3. Can't be keyword (var if switch care for while do) Or reserved words 
		4. Case sensitive 
		 standard 
		1. Hump nomenclature   example :appplePrice   redApplePrice
		2. See the name and know the meaning :
		3. Chinese is not recommended 

2.6JS Data type and type conversion

		1. value type =number
		 All arrays are numeric types ( Including binary 、 Hexadecimal 、 octal )
		NaN  It's not a number 
		- Integers 
		- decimal 
		- Scientific enumeration  10e5
		- Decimal system   octal   Hexadecimal   Binary system 
		-NaN(not a number) Not numbers 
		2. String type =string
		 Everything enclosed in quotation marks is a string 
		-”123“
		-‘123’
		3. Boolean type =boolean
		 Only two. (true and false)
		-true 
		-false
		4.null type = Empty type 
		 There is only one null

notes !: The detection return value is object

		5.undefined type = Undefined type 
		 only one undefined, No value 
		 Only declare unassigned :var a;
		- A declared variable can be assigned a value of  undefined

2.7 data type

 The detection shall be carried out in cooperation with the output , Such as :console.log(typeof('123'))

typeof: Keyword detection

		 grammar :
			typeof( The value to detect )
			typeof The value to detect 
			 Return value ( What happens )
			1. A certain data type (number string undefined object boolean)
			2. Returns... As a string 

isNaN:(is not number) Check whether a value is a number , If it is , Output is false

			var n1 = 100; console.log(isNaN(n1)); //=> false
			var s1 = 'Jack' console.log(isNaN(s1)); //=> true

2.8 Conversion of data types

			 Conversion between data types , Conversion between various data types 

2.8.1 For example, convert other data types to numerical values :

			 Method 1 :
					number( Variable )
							 You can cast a variable to a bit value 
							 Can convert decimal places , Keep decimals 
							 Boolean values can be converted 
										 If you encounter something that cannot be converted, you will return NaN
			 Method 2 :
					parseInt( Variable )
						 Check from the first , If it's a number, change it , Know that the first thing is not a number , Until a content that is not a number . If the beginning is not a number, it will be returned directly NaN.
						 I don't know the decimal point , Only integers can be retained 
			 Method 3 :
					parseFloat( Variable )
						 Check from the first , If it's a number, change it , Know that the first thing is not a number , It doesn't start with a number , Put it back directly NaN
						 difference : Know the decimal point once 

2.8.2 Convert other data types to strings

						- Variable .toString()
						-string( Variable )
						- Use + operation 

2.8.3 Other data types are converted to Boolean

						-Boolean( Variable ) stay js There are only ‘’、0、null、NaN These things false, What is the rest true.

JS The first day continued

Operator

1. Mathematical operators

1.+

	 Only when the symbol is a number twice will the addition operation be performed 
	 As long as either side of the symbol is a string type , String concatenation will be done 

2.-

	 Can perform multiplication 
	 It will automatically convert the values of the two passes into numbers for operation 

3.*

	 Can perform multiplication 
	 It will automatically convert the values of the two passes into numbers for operation 

4./

	 Can do Division 
	 It will automatically convert the values of the two passes into numbers for operation 

5.%

	 Can calculate the remainder 
	 It will automatically convert the values of the two passes into numbers for operation 

2. Assignment operator

1.=

 It's the assignment operation , Assign the value on the right of the equal sign to the variable on the left 

2.+=

var a = 10;
a += 10;
console.log(a);
// The value is 20
a += 10 Equivalent to a= a + 10

3.-=

var a = 10;

a -=10;

console.log(a);// The value is 0

a -=10 Equivalent to a = a - 10;

4.*=

a =10 Equivalent to a = a 10;

5./=

a /=10 Equivalent to a = a / 10;

6.%=

a %=10 Equivalent to a = a % 10;

Comparison operator

1.==

	 Compare the values on both sides to see if they are equal , Regardless of the data type 
	1=='1'  obtain true

2.===

	 Absolute equals sign 
	 Compare whether the values on both sides are exactly equal , Including data types 
	1=='1'  obtain FALSE

3.!=

	 It's not equal to   Compare the values on both sides to see if they are equal , When equal, we get FALSE
	1!='1'  obtain FALSE

4.!==

	 Compare whether the values on both sides are completely unequal , When equal, we get FALSE
	1!=='1' obtain  TRUE

5.>=

	 Compare the values on both sides to see if the left is greater than or equal to the right 

6.<=

	 Compare the values on both sides to see if the left is less than the right 

notes : Note the writing order of the operators

7.>

8.<

Logical operators

1.&&

 also : Both left and right sides need to be at the same time true It will take effect. 

2.||

 or : Only one is needed for the left and right true Effective 

3.!

 Reverse operation , Contrary to its own value 

Auto increment and auto decrement operator

1.++

	 Perform self increment operation 
	 Divided into front ++ And post ++
	var a=10;
	 In front of ++ Such as ,++a, Output is 11;
	 After ++ Such as ,a++, Output is a  Then take it. a The value of the into 11

2.--

	 Perform self subtraction 
	 The usage is the same as self addition 
原网站

版权声明
本文为[Mike_ JioDan]所创,转载请带上原文链接,感谢
https://yzsam.com/2021/12/202112142133221658.html