Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8501483
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T01:13:30+00:00 2026-06-11T01:13:30+00:00

1. >>> const a = 2 2. >>> var a = 3 3. >>>

  • 0
1. >>> const a = 2
2. >>> var a = 3
3. >>> a = 4
4. >>> a // print 2

Why the operation line 3 is allowed? const seems more “global” than without any keyword…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T01:13:32+00:00Added an answer on June 11, 2026 at 1:13 am

    This is is just how const works (or doesn’t work):

    Creates a constant1 that can be global or local to the function in which it is declared. Constants follow the same scope rules as variables [.. and cannot share a name] with a function or a variable in the same scope.

    Firefox [..] throws a TypeError if you redeclare2 [which is different than re-assigning] a constant. None of the major browsers produce any notices or errors2,3 if you assign another value to a constant [..] but the reassignment is unsuccessful (only) in Firefox and Chrome (at least since version 20).

    Note that const is not part of the ECMAScript 5 specification and the JavaScript 1.5 semantics will be re-defined in ECMAScript 6.

    Behavior will vary across browser implementations with respect to support and re-declaration/re-assignments semantics.


    1 In IE 9, using const a = 2 results in

    "Syntax error"

    2 In FF 14, const a = 2; var a = 3; a = 4; a, when evaluated as a single program, results in

    TypeError: redeclaration of const a

    which is different than executing each line one-at-a-time in the REPL. I suspect this is because var is hoisted above the const and because a const "cannot share a name with a function or variable in the same scope".

    3 In Chrome 21, const a = 2; var a = 3; a = 4; a evaluates to 2 with no warning or message.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code: const string LabelToFind = goTo considered Harmful; using (var file = new
class test { public: int data; test(int var = 0):data(var){cout<<constructor<<endl;} ~test(){ cout<<destructor<<endl; } test(const
I have this two functions: procedure TDisplay.CubAssign(VAR Obj: TCubObj; CONST bReleaseOnExit: boolean); begin ReleaseCubOnExit:=
I saw someone using this in one answer: void methodA(const int*& var); I couldn't
What is the meaning of using a constant in JavaScript? var and const do
A.as package { public class A { public static var someObject:Object = { (B.SOME_CONST):
<style> #test{ background-color:#b10515; width=440px; } </style> <script> ... ... cell[k]=document.createElement('td'); var cont = document.createElement('a');
const char *sentence = He was not in the cab at the time.; printf(\%s\
const string postdescWithComments = @<span class=footerLeft>posted on <a href={0} title = Permanent link to
const size_t size = 5; int *i = new int[size](); for (int* k =

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.