1. Introduction to JavaScript
* It is an object-based and event-driven language, which is applied to the client-side
- object-based
** provides a lot of objects, which can be used directly
- event-driven
** html for website static effects, JavaScript dynamic effects
- client Side: specifically refers to the characteristics of browser
* js
(1) interactivity
- dynamic interaction of information
(2) security
- js cannot access local disks
(3) cross-platform - cross-platform in Java, virtual machine - Only browsers that can support js can run * The difference between JavaScript and Java (Lei Feng and Lei Feng Pagoda) (1) Java is sun, now Oracle company; js is Wangjing company (2) JavaScript is object-based; Java It is object-oriented (3) Java is a strongly typed language; js is a typed language - such as int i = "10" in java; -js: var i = 10 ; var i = "10"; (4) JavaScript only It can be executed if it needs to be parsed, and Java needs to be compiled into a Zijie code file first, and then executed; *The composition of JavaScript (below js)
**When using the second method, don't write it in the script tag, and the code will not be displayed. 3. Java's primitive types and declared variables ** Java's basic data types (8) byte short int long float double char boolean ** All variables are defined with the keyword var ** jsde's primitive types (5) -string : string
*** var str="abc"; -number: numeric type *** var m=123; -Boolean: true and false *** var flag= true -null: *** var date = new Date(); *** Get the application of the object, null means that the application of the object is empty, so the application of the object is also object -undifined: *** Define a variable, no assignment *** var aa; **typeof(): View the data type of the current variable 4. js statements - statements in Java: ** if judgment ** switch statement ** loop for while do-while - these statements in js ** if judgment statement ** switch statement ** loop statement for while ** i++ and ++i are the same as Java } 5. js operators ** += ; x+=y ==>x=x+y ; ** In js, there is no distinction between integers and decimals - such as 1/100 in In Java it shows 0
What is displayed in js is 1
** The addition and subtraction of strings is the operation
var str = "123" ** If adding, it is the concatenation of strings ** If subtracting, it is subtracting Operation var str = "123"; * //String operation var str="456" //alert(str+1); //In Java it shows 4561, in js it is still 4561, * prompts NANA: Indicates that it is not a number **Boolean type can also operate *** If set to true: the equivalent value is 1; *** If set to false: the equivalent value is 0; ** The difference between == and === * *Make judgments ** ==Compare values ** ===Compare values and types **Introduce knowledge Statements output directly to the page (the content can be displayed on the page) * document.write("aaa") * document.write("<br>" ) ** can output variables, fixed values, HTML codes, function names to the page Syntax : function function name (formal parameter 1, formal parameter 2) { //some code
Function body
}
Calling syntax:
function name (actual parameter 1, actual parameter 2);
Note: After the function is written, it will not execute by itself, you need to call the function to execute
//Circle area function
<script type="text /javascript">
function mianji(n)
{
var mianji=3.14*n*n;
document.write("The area of a circle with radius "+n+" is "+mianji);
}
mianji(9);
</script>
return Value: return
var a={name:"Zhang San",age:10};
alert(a.age)
* It is an object-based and event-driven language, which is applied to the client-side
- object-based
** provides a lot of objects, which can be used directly
- event-driven
** html for website static effects, JavaScript dynamic effects
- client Side: specifically refers to the characteristics of browser
* js
(1) interactivity
- dynamic interaction of information
(2) security
- js cannot access local disks
(3) cross-platform - cross-platform in Java, virtual machine - Only browsers that can support js can run * The difference between JavaScript and Java (Lei Feng and Lei Feng Pagoda) (1) Java is sun, now Oracle company; js is Wangjing company (2) JavaScript is object-based; Java It is object-oriented (3) Java is a strongly typed language; js is a typed language - such as int i = "10" in java; -js: var i = 10 ; var i = "10"; (4) JavaScript only It can be executed if it needs to be parsed, and Java needs to be compiled into a Zijie code file first, and then executed; *The composition of JavaScript (below js)
**When using the second method, don't write it in the script tag, and the code will not be displayed. 3. Java's primitive types and declared variables ** Java's basic data types (8) byte short int long float double char boolean ** All variables are defined with the keyword var ** jsde's primitive types (5) -string : string
*** var str="abc"; -number: numeric type *** var m=123; -Boolean: true and false *** var flag= true -null: *** var date = new Date(); *** Get the application of the object, null means that the application of the object is empty, so the application of the object is also object -undifined: *** Define a variable, no assignment *** var aa; **typeof(): View the data type of the current variable 4. js statements - statements in Java: ** if judgment ** switch statement ** loop for while do-while - these statements in js ** if judgment statement ** switch statement ** loop statement for while ** i++ and ++i are the same as Java } 5. js operators ** += ; x+=y ==>x=x+y ; ** In js, there is no distinction between integers and decimals - such as 1/100 in In Java it shows 0
What is displayed in js is 1
** The addition and subtraction of strings is the operation
var str = "123" ** If adding, it is the concatenation of strings ** If subtracting, it is subtracting Operation var str = "123"; * //String operation var str="456" //alert(str+1); //In Java it shows 4561, in js it is still 4561, * prompts NANA: Indicates that it is not a number **Boolean type can also operate *** If set to true: the equivalent value is 1; *** If set to false: the equivalent value is 0; ** The difference between == and === * *Make judgments ** ==Compare values ** ===Compare values and types **Introduce knowledge Statements output directly to the page (the content can be displayed on the page) * document.write("aaa") * document.write("<br>" ) ** can output variables, fixed values, HTML codes, function names to the page Syntax : function function name (formal parameter 1, formal parameter 2) { //some code
Function body
}
Calling syntax:
function name (actual parameter 1, actual parameter 2);
Note: After the function is written, it will not execute by itself, you need to call the function to execute
//Circle area function
<script type="text /javascript">
function mianji(n)
{
var mianji=3.14*n*n;
document.write("The area of a circle with radius "+n+" is "+mianji);
}
mianji(9);
</script>
return Value: return
var a={name:"Zhang San",age:10};
alert(a.age)