Coggle requires JavaScript to display documents.
let data =54 data += 6 console.log(data) //60
const data = 54; data += 65; //TypeError: Assignment to constant variable. console.log(data) ; //54
const s = [5,6,7] s[0] = 6 //s [6,6,7]
const obj = {name: "vino",age: 5} Object.freeze(obj) ojb.name = "test" //obj {name: "vino",age: 5}
// function (return "666" ) const arrow = ( ) => "666"
const increment = (number, value = 1) => number + value increment(5,2 ) // 7 increment(5) //6
const sum = (...args) => { return args.reduce((x,y) => {return x+y}) } sum(1,2,3) //6
//Functions with ParametersPassed //带参数的function const myConcat = (arr1,arr2) => arr1.concat(arr2)
const arr1 =[5,7,6,"mamiya","pentax"] const arr2 =[...arr1]
const arr = [1,2,3,4] arr.forEach((element) => console.log(element))
function pow(x){ return x* x } let arr = [1,3,4,5] result = arr.map(pow) // [1,9,16,25]
let arr = [ 4,5,6] arr.reduce(function(x,,y){ return x +y}) //15
var arr = ["a","b","c"] var r = arr.filter(function (element,index,self) { console.log(element) // a, b,c console.log(index) // 0 ,1,2 console.log(self) //arr return true })
cosnt arr = [10, 2 ,40,5] arr.sort(function(x,y){ if(x>y){ return 1} if(x<y){ return -1} return 0 }) //[2,5,10,40]
class Name { constructor(props){ this.name = props }} const newName = new Name("vino")
class Book { constructor(author){ this._author = author } //getter get writer (){ return this._author } //setter set writer (updatedAuthor){ this._author = updatedAuthor } } const lol = new Book('anyone') console.log(lol.writer) //anyone lol.writer = "wot" console.log(lol.writer) //wot
import {demoX} form "demo" //从demo中导入demoX import * as demo from "demo" // 导入dmeo
cosnt capitalizeString = (string) => { return string.charAt(0).toUpperCase + string.slice(1) } export {capitalizeString} //导出函数 export const foo = "bar" //导出变量
export default function add(x,y) { return x+y }
const user = {name: "vino", age: 5} const {name : userName,age: userAge} = user //定义 赋值 userName userAge 变量
const [a,b,...arr] = [1,2,3,4,5,6] console.log(a,b,arr) // 1,2 ,[3,4,5,6]
const demo ={ name: "vino, age: 8 }
const demo = {naem: "vino",age : 5} console.log ("this is demo name ${demo.name} !")