Most voted "variables" questions
A variable is a named data storage location in memory. Using variables , a computer program can store text numbers, binary data, or a combination of any of these data types. They can be transferred in code, to other functions and even other applications.
Learn more…645 questions
Sort by count of
-
38
votes3
answers5488
viewsHow to use the current value of a variable in a more internal function?
The following code "prints" 50 times the text "Message 50" in a textarea. for (var i = 0; i < 50; i++) { setTimeout(function() { textArea.value += 'Mensagem ' + i + '\n'; textArea.scrollTop =…
-
38
votes3
answers96047
viewsWhat is the use of a static or final variable in java?
What is the difference of the declaration private static int var_nome for private final int var_nome for private int var_nome? How these statements can influence my algorithm?…
-
38
votes2
answers2688
viewsWhy do you usually declare a variable with default value?
In several applications that have been written with strongly typed languages, a variable (usually) is declared with its default value. Example: int x = 0; double y = 0; However, it is possible to…
c# variables characteristic-language typing variable-declarationasked 7 years, 4 months ago UzumakiArtanis 9,534 -
29
votes1
answer1530
viewsProperty Vs variables
I’ve always used properties in C# this way: public int Numero { get; set; } Today I asked myself, why do I use this get and set instead of a variable? Is there a difference? I only use it that way…
-
27
votes3
answers983
viewsWhat is a variable?
We always use variables all the time in codes. Is it the same thing we learn in mathematics? How does the variable work?
terminology variables pattern-design software-engineering computer-scienceasked 7 years, 9 months ago Maniero 444,682 -
24
votes4
answers1016
viewsIs the use of "private" in C# classes optional?
What’s the difference between private string abc = ""; and string abc = "";? Is there any difference or is it just the way you write that changes? I did a test with and without the private and saw…
-
21
votes2
answers8317
viewsHow to delete a variable in Javascript?
I program in other languages, I’m still starting in Javascript. I was testing the mgibsonbr response code to this question and found a difficulty that may be trivial. If I define var x = 0 in the…
-
20
votes7
answers43303
viewsHow do I know if a variable is of the Javascript Number type?
In javascript, because there is no declaration of the types of variables such as Integer, String, Boolean, etc., it is a difficult task to know what kind of value you are dealing with in a given…
-
20
votes3
answers32049
viewsHow to check if a variable is set?
I tried to do it that way: else if (vCodUG === undefined) and made an error of: Uncaught Referenceerror: vCodUG is not defined…
-
19
votes2
answers234
viewsHow to reference the current board
As an example, using the variable SCRIPT_FILENAME we can get the requested file, but for this problem we want to get the directory where the file is .htaccess: # Rewrite the url <IfModule…
-
17
votes3
answers72012
viewsGlobal variable in Javascript
How to make a global variable in Javascript? I need the variable that was declared in one function to work in another function. Example: Jsfiddle $("#div3").click(function() { var fill = "a"; });…
-
17
votes4
answers1239
viewsFormat city names and ignore words like "do", "dos", "das", "da", etc
I’m working with Webservice whose city names are all out of shape and I’d like to create a function to treat the names evenly. An example is this: CHICKEN HARBOR I’d like to keep it that way: Porto…
-
17
votes2
answers1267
viewsWhat is the difference between String[] args and String args[]?
What is the difference between the statements String[] args and String args[] in Java?
-
16
votes3
answers675
viewsWhy can’t I declare an attribute using the var keyword?
The keyword var allows me to declare typed variables, and allows variables to be defined implicitly. Example: var i = 10; The compiler will assume that my variable i is of the whole type int.…
-
16
votes3
answers1076
viewsIs it correct to prefix variable names with their type?
It is usual/correct to use variables where the first letter references their typing? Ex.: string sVariavel; int iVariavel;, etc.... EDIT: The name of it is hungarian notation. Is that good practice?…
-
16
votes4
answers634
viewsWhat is the difference between i += 2 and i = i + 2?
I was seeing, there are people who speak that is different and there are those who speak that is the same thing. I am confused. They are different or do the same thing?
-
15
votes1
answer3438
viewsvar, const or Let? Which to use?
I recently discovered the existence of let and const but now I’m in doubt which one to use constantly? And why I never see codes with let or const?…
-
15
votes2
answers1034
viewsWhy does the absence of the suffix L cause the long variable to be interpreted as int?
When I use a short number for long, as long long1 = 9797;, the number is accepted even without using the suffix L. However, by placing a higher number - as its minimum and maximum values, for…
-
15
votes1
answer346
viewsWhat is the alternative of 'And' in Portuguese for variable names and methods?
One question that always bothers me when I’m in a Java project where we use Portuguese terms is dealing with method names or variables that represent, somehow, two things and I need to mention both…
-
14
votes1
answer137
viewsRFC6530 - Check if variable contains a well formatted PHP email address
Approval adopted by the Gmail as published in Official Gmail Blog, and as defined in RFC 6530: Assuming a function valida_email() that would return boolean: echo valida_email("té[email protected]"); //…
-
14
votes5
answers1721
viewsIs it possible to change the type of the variable in Java?
Is it possible to change the type of my variable in Java? For example, I created a variable x, she being a Double: double x; I want to continue using my variable x but she is now a int: int x;…
-
14
votes2
answers1423
viewsJavascript - Access variable
Situation I am deepening my study a Javascript, and I came up with a little doubt. In closure, encapsulation and variable scope, all show how to use the var and talk about Local and Global scope,…
-
14
votes1
answer615
viewsHow does the lifespan of static variables work?
I just saw a question about C. In it the following code was shown: #include <stdio.h> int main() { static int a = 5; printf("%d", a--); if(a) main(); return 0; } Example running on repl.it.…
-
13
votes3
answers1124
viewsJavascript Access Modifiers
Situation function x(){ var f = null; // PROPRIEDADE PRIVADA DE x this.a = null; // AS INSTANCIAS DE x TERÃO ACESSO A PROPRIEDADE a x.b = null; // ACESSIVEL COMO x.a } function y(){ x.call(this); //…
-
13
votes2
answers6067
viewsWhat’s the difference in instantiating, initializing, and declaring a variable?
Many articles on the Internet refer to these verbs, regardless of the programming language. But sometimes they are all confused or exchanged, which creates a lot of confusion. Which means…
variables terminology variable-declaration language-independent initializationasked 7 years, 9 months ago vinibrsl 19,711 -
13
votes5
answers1023
viewsWhat is the difference between starting an empty variable and starting directly with the value?
I see things like: $arr = []; $var = ''; $var; $var = null; What’s the difference between starting the variable like this: $var = ''; $var = 'teste'; And start like this: $var= 'teste';…
-
12
votes2
answers396
viewsIs there a function to display the defined variables?
There is a way to give a "var_dump" in all instantiated variables in that context, without having to put each one inside the var_dump()?
-
12
votes1
answer2292
viewsHow to create objects (variables) with different names within a loop?
I want to generate different databases in a loop. In the example below would be 3 distinct databases with the following names: "data1", "data2", "data3". for (n in 1:3){ dados<-paste0("dados",n)…
-
12
votes1
answer225
viewsDoes the name size of a variable affect your weight?
There’s a size difference between that: string packet1234 = "123"; And that? string packert1234556 = "123";
-
12
votes1
answer129
viewsHow to extract the path to the file
In a variable that contains the path to a file and its name, the file name can be extracted as follows: #!/bin/bash filenamepath="/caminho/para/ficheiro.pdf" filename=$(basename $filenamepath) Which…
-
12
votes3
answers366
viewsVariable in main is global?
I read that global variables are those that we declare outside of all functions using #define and this way they could be used by all functions of a program. However, I was informed that the…
-
12
votes2
answers52864
viewsHow to check if the Term is contained in String in PHP?
I need to check if a certain tag is inside the string. I get this string from the database that comes in the form of tags comma separated without spaces as below: String canais,proteses,implantes…
-
12
votes3
answers172
viewsWhat is the difference in the 3 types of variables and how do they behave in the compiler?
For test questions, I made the following code: static int valor1 = 10 / 5; static int valor2() => 10 / 5; static int valor3 => 10 / 5; public static void Main() {…
-
12
votes2
answers482
viewsWhat would be the "identity" of an object?
Reading more about objects, trying to "detach" me from the concept that object would only be provided with a "class", in this answer, I saw the following sentence: "Objects have identity. A variable…
-
12
votes2
answers286
viewsWhy does the exchange of values via de-structuring not work if we do not use semicolons?
We know that the semicolon is optional in Javascript, even always prefer not to use it. If I want to exchange values between two variables, via unstructuring, I can do: let a = 11; let b = 22; [a,…
-
11
votes7
answers811
viewsHow to write variables in PHP?
I was watching the videos of Robson V.Leite and I realized that at a given moment he retrieves information from the forms to enter into the database in a different way than I use, the only way I…
-
11
votes3
answers1792
viewsIs it a good idea to declare variables with accents?
I was taking a look at the PHP Handbook on the variables. There I found an excerpt of code that left me with the "foot behind". $täyte = 'mansikka'; // válido; 'ä' é um caracter ASCII (extendido)…
-
11
votes1
answer363
viewsCustom global variable
In that question here, I explained that I was afraid to save my settings in the variable $GLOBALS because she turns my settings into global values, then the guy answered me that there was no…
-
11
votes3
answers935
viewsWhy does Javascript allow using variables without declaring?
I was doing a test on Jsfiddle, with the code below. In it I did not declare the variable i, but still, I can use it normally. Is that intentional or is it a flaw? So, I can just go out using…
-
11
votes1
answer173
viewsConstant is really useful?
Why would I use a constant instead of a variable? In addition to readability, there is another gain in using a constant? I can’t make a difference that makes me use a constant instead of a variable.…
-
11
votes2
answers2954
viewsWhat is a scalar variable?
I was reading the PHP documentation and a function is_scalar() - as stated by the site itself - when it is used it will inform if a certain variable is scalar. However I wanted to know a little more…
-
11
votes1
answer112
viewsDoes creating local variables all the time generate extra cost for the software?
I made a program of which he writes variables all the time, and with that generated me a doubt, instantiating a variable all the time generates more cost than just assigning the value to an existing…
-
11
votes3
answers189
viewsWhy do we not receive an error when we call an undeclared variable as a window property?
We initially have this: var a = 0; console.log(window.a === a); // true Okay, so here we prove that when we declare a variable in global scope, it becomes a property of the object window. Now, we…
-
10
votes8
answers7818
viewsCheck if variable contains a well formatted PHP email address
The variable receives a value that is supposed to be an email address, but doubts arise: It will be an email address, random text, or anything else? Being an email address, it is well formatted?…
-
10
votes2
answers808
viewsWhat are the size limits of variables in Ruby?
I would like to know the size limit of variables of the following types: String - How many characters can I have in a single string? Integer and Float - What is the largest and smallest number that…
-
10
votes3
answers5279
viewsHow to check if a variable was set in Python?
Is there any way to check whether a variable was set in Python or not?
-
10
votes1
answer400
viewsIs it good to use global variables for greater readability in the code?
I am implementing an exercise of the Deitel book, How to Program C, 6th edition, the Logo problem in chapter 6. It was an interesting question with legal logical problems etc. The only question of…
-
10
votes5
answers860
viewsWhy is a variable with no value considered uninitiated?
I realized that PHP returns that a variable has not been started if it has no value assigned to it. In my opinion, it makes no sense because the variable has already been started and awaits a value.…
-
10
votes1
answer382
viewsShould we use all variables as private?
We should always use the attributes of a class as private? What private variables help prevent? How do you decide whether a particular property should be private or not? CASE, by default, each…
php oop variables software-engineering encoding-styleasked 7 years, 6 months ago UzumakiArtanis 9,534 -
10
votes1
answer4428
viewsWhat’s the difference in Kotlin between var and val?
Learning Kotlin I came across the following doubt, according to the documentation: Classes in Kotlin can have properties. These can be declared as mutable, using the var keyword or read-only using…