JavaScript基础学习笔记
前言把JS代码从发html中剥离能更好管理代码实现每个代码的职责单一所以我写了以下代码console.log(my first js code!);!DOCTYPE html html langen head meta charsetUTF-8 meta nameviewport contentwidthdevice-width, initial-scale1.0 titleDocument/title /head body h1Hello World!/h1 phello world!/p script srcindex.js/script /body /html变量与常量var(不常用 全局作用域)let --- 可以被修改const --- 不能被修改声明时就要初始化。数据类型StringNumberBooleannullundefinedconst name jack; const age 18; const rate 0.45; const isEmpty true; const x null; const y undefined; let z;//undefined console.log(typeof name); console.log(typeof y); console.log(name);代码的连接console.log(my name is name and my age is age); console.log(my name is ${name} and im ${age} years old.\n); const hello my name is ${name} and im ${age} years old.\n; console.log(hello);字符串内置方式const a hello world!; // console.log(a.length);//因为是属性所以没有()有括号的是方法 console.log(a.substring(0, 5).toUpperCase()); console.log(a.split( ));数组const arr new Array(1,2,3,4,5,6,7,8,9); const fruits [apple, banana, peach, 10, false]; console.log(arr, fruits); console.log(arr[5]); fruits.push(mango); fruits.unshift(watermalon); fruits.pop(); console.log(fruits);const person { name: dom, age: 18, hobbies: [music, basketball, movies], address:{ street: 8 main st, city: shanghai, state: china, }, }; person.email domshishuaige123.com; console.log(person.email);JASON格式输出const peoJSON JSON.stringify(person); console.log(peoJSON);操作符 值相同类型不相同 值和类型都相同
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2420116.html
如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!