Variable types within JavaScript

I’ve just discovered if I set up a variable this way:```
var vSeven = 2;


var vSeven = 0;
vSeven = 2;


it is.

My question is -- why is this two-step approach required in JavaScript? Superficially it would appear that zero is recognized as an integer but "2" isn't. Glad I tripped over the solution to my coding problem, but I'm misunderstanding something fundamental about JavaScript.

I discovered this reality when coding a SQL query. If I set up a variable as:```
var vSeven = 2;
```the query failed. But if I ammended it to:

var vSeven = 0;
vSeven = 2;


it worked.

This is impossible Morley.
The right side of your expression (in this case “2”) always determines what kind of variable you will end up with.

You can check this by adding

var variableType = typeof(vSeven ) //returns objectType of variable
application.output(variableType); //check output TAB in script editor

Must be something else.

maarten:
This is impossible Morley.
The right side of your expression (in this case “2”) always determines what kind of variable you will end up with.

You can check this by adding

var variableType = typeof(vSeven ) //returns objectType of variable

application.output(variableType); //check output TAB in script editor


Must be something else.
var vSeven = 2;
var vType = typeof(vSeven)
application.output(vType); // returns "number"

Returns “number” also if I start with var vSeven = 0;

The field to be searched, company.com_sev_id, is an integer field. Now here’s the SQL query. This version works:

var vSeven = 0;
vSeven = 2; // test
// vSeven = globals.gsevid;
var vMaxReturnedRows = 100000;
var vQuery = "SELECT * FROM company WHERE ";
vQuery += "company.com_sev_id = ? AND company.company_id NOT IN ";
vQuery += "(SELECT cr.comid FROM cr WHERE company.company_id = cr.comid ) ";
vQuery += "AND (company.cr_status = 0 OR company.cr_status IS NULL) ";

var vDataset = databaseManager.getDataSetByQuery(controller.getServerName(),vQuery,[vSeven],vMaxReturnedRows);
controller.loadRecords(vDataset);

And here’s the version that does not.

var vSeven = 2; // test
// vSeven = globals.gsevid;
var vMaxReturnedRows = 100000;
var vQuery = "SELECT * FROM company WHERE ";
vQuery += "company.com_sev_id = ? AND company.company_id NOT IN ";
vQuery += "(SELECT cr.comid FROM cr WHERE company.company_id = cr.comid ) ";
vQuery += "AND (company.cr_status = 0 OR company.cr_status IS NULL) ";
var vDataset = databaseManager.getDataSetByQuery(controller.getServerName(),vQuery,[vSeven],vMaxReturnedRows);
controller.loadRecords(vDataset);

The good news is I have code that works. The not-so-good news is I don’t understand why it works. :?