回顾java中的变量
JS中的变量
JS函数
全局变量
实现代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS变量 函数</title>
</head>
<body>
<script>
// var i=1;
// i="afsd";
// i=123.2;
// i=new Object();
// i=true;
// window.alert(i);
/*qwewq*/
// var i;
// window.alert(i)
// window.alert(undefined);
// var k=undefined;
// window.alert(k);
// window.alert(age);
// var a,b,c=200;
// window.alert(c);
// a=false;
// window.alert(a);
// a="qewr";
// window.alert(a);
// function sum(a,b){
// window.alert(a+b);
// }
// sum(10,20);
// sayHello=function(username){
// window.alert("hello "+username);
// }
// sayHello('jack');
function sum(a,b){
return(a+b);
}
// var returnValue=sum(10,2.2);
// window.alert(returnValue);
// var rv=sum("jack");
// window.alert(rv);
// var rv =sum();
// window.alert(rv);
// function test(username){
// window.alert(username);
// }
// function test(){
// window.alert(12314);
// }
// test("jack");
// var i=100;
// function test(){
// window.alert(i);
// }
// test();
// var username='jack';
// function test(username){
// var username="chenglong";
// window.alert(username);
// }
// test(username);
// window.alert(username);
// test=function(){
// username="javk";
// }
// test();
// window.alert(username);
</script>
<!-- <input type="button" value="hello" οnclick="sayHello('jack')"> -->
</body>
</html>
JS数据类型
Undefined
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>JS数据类型</title>
</head>
<body>
<script>
// function test(a,b){
// if(typeof a=="number"&& typeof b=="number"){
// return a+b;
// }
// window.alert(a+","+b+"必须都为数字");
// }
// var value=test(false,"abc");
// window.alert(value);
// var a=null;
// var i=typeof a;
// window.alert(i);
// test=function(){
// }
// window.alert(typeof test);
// var obj=new Object();
// window.alert(typeof obj);
// var i;
// var a=undefined;
// window.alert(i==a);
// var s="undefined";
// window.alert(s==a);
// window.alert(10/0);
// window.alert(10/3);
// function test(a,b){
// if(isNaN(a)||isNaN(b)){
// alert("参与运算的必须是数字")
// return;
// }
// return a+b;
// }
// test(100,"asd");
// alert(test(100,200));
// alert(Math.ceil("2.1"));
// alert(parseFloat(12.123));
// alert(parseInt(12.45));
</script>
</body>
</html>