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

  • SEARCH
  • Home
  • 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 8992049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T22:51:58+00:00 2026-06-15T22:51:58+00:00

I want to do sth like this (c++): const int SIZE = 5; int

  • 0

I want to do sth like this (c++):

const int SIZE = 5;
int array[SIZE];

but in JS. I’m using the SIZE value many times (for many arrays and later in the code) and I don’t want to put many literals with the same value (in case I have to edit it later). I read somewhere that there’s a const keyword in JS but it doesn’t work in every browser (not sure if that’s true but I want a universal solution). And the shorter/simpler the better! 😉

  • 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-15T22:51:59+00:00Added an answer on June 15, 2026 at 10:51 pm

    The const keyword is in fact non-standard, and only implemented by Mozilla therefore not guaranteed to work cross-browser (but apparently some browsers implement it, see the link on Bergi’s answer). Just use a regular variable, and the uppercase name to indicate it’s supposed to be a constant:

    var SIZE = 5;
    var arr = new Array(SIZE);
    

    Note: if you pass anything other than a number to the Array constructor, it will create an array with length and the value you passed at index 0. In that case, it’s best to just use the literal notation (var arr = ['foo']). Also keep in mind that when you pass a number to the constructor, you’re just setting the initial length, and it’s always possible to add or remove elements after that.

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

Sidebar

Related Questions

want to know why String behaves like value type while using ==. String s1
I want to do sth. like this: foo=(a b c) foo-=b echo $foo #
i want to do sth like this: <HierarchicalDataTemplate x:Key=BuildingTemplate ItemsSource={Binding Path=RoomAccesses.Select(p => p.Room)} ItemTemplate={StaticResource
How to construct new variable in C#. I mean, to have sth like this
i have these: a=sc.array([0,1]) b=sc.array([1,0]) c=sc.array([0,-1]) d=sc.array([-1,0]) orientation_list=(sc.array([a,b,c,d])).tolist() #--------------------------------------------------------------------- #i am trying sth like
I've got sth like that: #include <iostream> using namespace std; class FirstClass { public:
I have a code like this: fork(); if child: execvp(sth); //Just returns if errors
Atm i have sth like that: template<int n> struct Pow { enum{val= Pow<n-1>::val<<1}; };
Want the function to sort the table by HP but if duplicate HPs then
want to rewrite urls like site.com/software to wp-content/themes/dir/software.php and something is not working.. Here's

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.