A thought came to mind to see if JavaScript’s const can be used with string. At first I ran some code on my own then went to this link from googling the question and went in here:
Although different language, as this is via JavaScript, I coded what I saw in the link above and ran it in JavaScript:
const HELLO3 = “What’s Up?”;
undefined
// Received an error.
console.log(HELLO3);
VM995:2 Uncaught ReferenceError: HELLO3 is not defined(…)(anonymous function) @ VM995:2InjectedScript._evaluateOn @ VM246:878InjectedScript._evaluateAndWrap @ VM246:811InjectedScript.evaluate @ VM246:667
// Versus within a regular variable
var Hello2 = “What’s up?”;
undefined
console.log(Hello2);
VM1338:2 What’s up?
undefined
???JAVASCRIPT issue (bug) with CONSTANT, am I wrong???
Example running this code in not only Chrome (Version 49.0.2623.112 (64-bit)) as I’m on OsX 10.8), but also within Safari. Then I tried it with what I originally know constants are used for, with numbers. I ran below sample example from:
// It would seem that there is issue with numbers as well.
const MY_FAV = 7;
undefined
// according to MDN, this next line of code is supposed to show an error, but 20 popped up as if correct output
MY_FAV = 20;
20
// ran the console to reveal that the later defined value (20) comes out (bug)
console.log(MY_FAV);
VM257:2 20
undefined
// decided to write this constant variable out again on the browser console console, just out of thought
const MY_FAV = 7;
undefined
// and the output came out as 20 when called for
console.log(MY_FAV);
VM435:2 20
undefined
// ran same const within Safari browser. (at first all code was executed in Chrome)
const MY_FAV = 7;
< undefined
console.log(MY_FAV);
[Log] 7
< undefined
MY_FAV = 20;
< 20
console.log(MY_FAV);
[Log] 20
< undefined
const MY_FAV = 7;
< undefined
console.log(MY_FAV);
[Log] 7
< undefined
// my Firefox browser caught the error though:
const MY_FAV = 7;
undefined
console.log(MY_FAV);
7
undefined
MY_FAV = 20;
TypeError: invalid assignment to const `MY_FAV’
Again,
???JAVASCRIPT issue (bug) with CONSTANT, or am I wrong???