实例
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>JS演示</title> </head> <body> <script> // alert('弹窗提示'); //使用var关键字来定义变量 var name='小新'; console.log('我的名字是'+name); //字符串类型 console.log(typeof(name)); //数组类型 var name1=['小新','小白','小黑']; console.log(typeof(name1)); console.log(name1); //对象 var obj=new Object(); console.log(obj); //数值类型 var sum1=10; console.log(typeof(sum1)); var sum2=5; var sum=sum1+sum2; console.log(sum1+'+'+sum2+'='+sum); //js表达式 if(sum1<sum2){ console.log(sum1+'比'+sum2+'小'); }else{ console.log(sum1+'不比'+sum2+'小'); } //js定义函数的方法, function Sum(num1,num2){ return num1*num2; } var num=Sum(10,20); console.log(num); var ls=function (num3,num4){ return num3+num4; } console.log(ls(15,22)); </script> </body> </html>
运行实例 »
点击 "运行实例" 按钮查看在线实例
简单的学习了JavaScript的变量定义,数据类型,以及定义函数的方法