js基础
/*如果是window.alert(),window可以省略*/ window.alert(‘yhs‘);
document.write(‘hello!js‘);
<body> <p id="one"></p> <script type="text/javascript"> document.getElementById(‘one‘).innerHTML = "helloworld"; </script> </body>
console.log(‘i am a boy‘);
2.js语句和注释
<script type="text/javascript"> var a = 1; //js语句标识符 var if for function b () { var c = 2; } b(); // /** * */ </script>
3.js数据类型
var x; //x 为undefined var y = 5; //y 为数字 var z = "John"; //z 为字符串 var a = false; //a 为布尔 var b = new Array(); b[0] = "xxx"; var b = new Array("aaa","bbb","ccc"); var b = ["aaa","bbb","ccc"]; //javascript对象 var person ={ firstname:"John", lastname:"Doe", id:5566}; console.log(person.firstname); console.log(person["firstname"]); //可以通过将变量的值设置为null来清空变量 var car = null;
4.js变量
5.js函数
<script type="text/javascript"> var c = function () { } c(); function b() { } b(); </script>
function d() { return "this is return function"; } var d1 = d(); console.log(‘this is a d1: ‘,d1);
//控制台输出this is a d1: this is return function
原文:https://www.cnblogs.com/yangHS/p/10848173.html