I see many project and many code, all code understand properly but in code one thing i don’t understand to declare variable, so please describe the actually why it declare ?
var query = {};
>Solution :
In javascript, a variable can store all types of data without declaration. But when there is a need to store data in form of key-value pairs, it’s necessary to define an object scope and then assign values using keys.
Example 1 (Correct way)
var a = {};
a.kwy1 = 10;
a.kwy2 = "Ten";
console.log(a);
Example 2 (incorrect)
var b; //here though b is declared, its not initialised with object scope. so it will give an error - Uncaught ReferenceError: b is not defined
b.kwy1 = 10;
b.kwy2 = "Ten";
console.log(b);
Example 3 (incorrect)
//here though c is not declared so will give an error - Uncaught ReferenceError: c is not defined
c.kwy1 = 10;
c.kwy2 = "Ten";
console.log(c);