JavaScript const Keyword

前端 未结 8 1657
自闭症患者
自闭症患者 2020-12-09 13:25

Does the const keyword in JavaScript create an immutable reference to immutable data structures? [I\'m assuming that immutable data structures exist in JavaScri

8条回答
  •  抹茶落季
    2020-12-09 13:54

    For example:

    const basket = [1,2,3];
    
    //Even though the variable is declared as const this one works
    basket[0] = 1111;
    console.log(basket);
    
    //This one throws an error
    basket = "Other primitive type."

提交回复
热议问题