Questions tagged [var]

var is a keyword in a number of programming languages.

In computer programming, a variable or scalar is a storage location paired with an associated symbolic name (an identifier), which contains some known or unknown quantity of information referred to as a value.

The variable statement declares a variable, optionally initializing it to a value.

In C# it is used to declare a variable of an implied type.

Beginning in Visual C# 3.0, variables that are declared at method scope can have an implicit type var. An implicitly typed local variable is strongly typed just as if you had declared the type yourself, but the compiler determines the type. The following two declarations of i are functionally equivalent:

 var i = 10; // implicitly typed
 int i = 10; //explicitly typed

References:

2462 questions
15
votes
1 answer

let var or var to let

In the last couple of months, I've been learning a lot about JavaScript. Having abused the languages for years, I dare say that I now have a better understanding of the language and I've come to love the benefits of its functional nature. Lately…
Elias Van Ootegem
  • 74,482
  • 9
  • 111
  • 149
14
votes
4 answers

Does C# pick the wrong type for var when parsing a dynamic object?

I am using the following code to convert some Json into a dynamic object. When I use DateTime.Parse on a property of my dynamic type I would expect the var to guess that it's type is a DateTime... instead, it stays as a dynamic. This can't be right,…
Mark Withers
  • 1,462
  • 5
  • 16
  • 34
14
votes
6 answers

How to create LINQ Query from string?

I am new at LINQ and really need a help with some coding. At the moment, I have a string and a var variables. string temp = "from product in myEntities.Products where product.Name.Contains(_Name) select product"; var _Products =…
Sammm
  • 501
  • 4
  • 9
  • 25
14
votes
2 answers

Redefined variable not success

For the following code, as I have redeclared a with var a, my expectation for alert(a) is to show undefined, but why it shows 4? function f(a) { var a; alert(a); } f(4);
user5768866
14
votes
4 answers

Why use var instead of the class name?

Possible Duplicate: What's the point of the var keyword? What advantages does using var have over the explicit type in C#? I always see other people producing code like: var smtp = new SmtpClient(); But why use var instead of SmtpClient in this…
Liam McInroy
  • 4,339
  • 5
  • 32
  • 53
13
votes
5 answers

How do JavaScript variables work?

I know that JavaScript vars point to a value: var foo = true; //... later foo = false; So in that example I've changed foo pointing to true -> foo pointing to false, but if I do: for (var i=0; i<100; i++){ var someVar = i; } Am I creating a…
pjnovas
  • 1,086
  • 1
  • 8
  • 24
13
votes
2 answers

javascript global variable with 'var' and without 'var'

Possible Duplicate: Difference between using var and not using var in JavaScript I understand that I should always use 'var' to define a local variable in a function. When I define a global function, what's the difference between using 'var'…
Moon
  • 22,195
  • 68
  • 188
  • 269
13
votes
4 answers

What is the purpose of 'var'?

Possible Duplicate: What's the point of the var keyword? I'm not asking how it works. I am not asking if it affects performance. I already know those answers. I want to know what inspired the MS C# team to add it to the language in the first…
Brent Arias
  • 29,277
  • 40
  • 133
  • 234
13
votes
2 answers

TypeError: Cannot destructure property `db` of 'undefined' or 'null'

I am getting a TypeError in my variable assignment for mongodb connection. Is there a workaround for this? //server.js var mongoose = require('mongoose'); var config = require('./config'); var { db: {user,pass,host,port,name } } = config; var…
temesgen
  • 161
  • 1
  • 2
  • 8
13
votes
1 answer

Difference between var and Symbol in sympy

Is there any difference between the two methods var and symbol in the sympy module in python? cause both are working the same way. I googled it and I did not find a detailed explanation for a difference. Are they really the exact same thing or one…
Safwat Alshazly
  • 331
  • 4
  • 11
13
votes
9 answers

What advantages does using var have over the explicit type in C#?

Possible Duplicates: What’s the point of the var keyword? Use of var keyword in C# I understand how IEnumerable<...> for a datatype can make the code a little less readable or how nested generics can seem a little daunting. But aside from code…
Corey Ogburn
  • 24,072
  • 31
  • 113
  • 188
13
votes
9 answers

See the type of a var in Visual Studio

Is there a way to see the type of a var within the Visual Studio 2013 code editor? When I have a crazy linq query it would be nice to see what the resulting type will be. I don't want to replace the var keyword with the actual type, I just want to…
user4007604
12
votes
1 answer

Redefining a local variable with var in JavaScript

I have a rather general question regarding JavaScript and local variables. My question is what is the difference between the following and if there is any: function bla { var a = 2; // local variable a = 3; // the local variable a…
Sentropie
  • 249
  • 1
  • 4
  • 14
12
votes
3 answers

'let and 'var' are the same in Typescript?

I was taking a look at AngularJS 2 and Typescript and I decided to make something with this just to learn the basics of Typescript. With many research I found good topics about modules, Typescript, and one of them was talking about the 'let' and…
Edie Johnny
  • 513
  • 2
  • 5
  • 14
12
votes
2 answers

Why is this javascript for loop running only once?

function f1() { for (i = 0; i <= 5; i++) console.log(i); } function foo() { for (i = 0; i < 5; i++) f1(); } foo(); Hi, I'm trying to understand why the result of executing foo is: 0 1 2 3 4 5 And…
Kam
  • 225
  • 2
  • 3
  • 6