[var , let , const] scope - 3

soom·2020년 8월 17일
1
post-thumbnail
post-custom-banner

3. const


1st. example

const abc = "test";

function example() {
  console.log("inside_block: ", abc);
}

example();
console.log("outside_block: ", abc);

result

inside_block: test
outside_block: test


2nd. example

const abc;
abc = "test"

function example() {
  console.log("inside_block: ", abc);
}

example();
console.log("outside_block: ", abc);

result

SyntaxError: Missing initializer in const declaration


3rd. example

const abc = "test";

function example() {
  const abc = 123;
  console.log("inside_block: ", abc);
}

example();
console.log("outside_block: ", abc);

result

inside_block: 123
outside_block: test


4th. example

const abc = "test";

function example() {
  abc = 123;
  console.log("inside_block: ", abc);
}

example();
console.log("outside_block: ", abc);

result

TypeError: Assignment to constant variable.


profile
yeeaasss rules!!!!
post-custom-banner

0개의 댓글