Typescript学习系列---《const》

'use strict'

const fruit = 'apple' ;

fruit = banana;

console.log(fruit);  // error

/**
 * attention: const仅限制变量赋值的操作,而不是变量本身的值
 */

const fruit = [];

fruit.push('apple'); //right
fruit.push('pear'); // right

fruit = []; //wrong 重新分配fruit

const与java StringBuffer类似,仅限制变量而不是变量代表的值。

发布了81 篇原创文章 · 获赞 10 · 访问量 2897

猜你喜欢

转载自blog.csdn.net/A_bad_horse/article/details/105008675
今日推荐