With var obtener_teclas = {}
you are simply defining the variable obtener_teclas
as an empty object of zero length.
var obtener_teclas = {}
console.log(typeof(obtener_teclas));
console.log(obtener_teclas);
console.log(Object.keys(obtener_teclas).length);
//Otras formas de crear un objeto vacío
console.log("*****");
var obtener_teclas2 = Object.create(null);
console.log(typeof(obtener_teclas2));
console.log(obtener_teclas2);
console.log(Object.keys(obtener_teclas2).length);
console.log("*****");
var obtener_teclas3 = new Object();
console.log(typeof(obtener_teclas3));
console.log(obtener_teclas3);
console.log(Object.keys(obtener_teclas3).length);
You could initialize the object with values:
var obtener_teclas = {v: "Valor1", v2: "Valor2"};
console.log(typeof(obtener_teclas));
console.log(obtener_teclas);
You can also add values to the a posteriori object:
var obtener_teclas = {};
console.log(obtener_teclas);
obtener_teclas.v = "Valor1";
obtener_teclas.v2 = "Valor2";
obtener_teclas.v3 = "Valor3";
console.log(obtener_teclas);
Regarding var x;
you are creating the variable x
as undefined
.
If you want more info about declaration of variables in JS I recommend this question
And here more info on the creation of objects.
Also check out the use of "use strict"
in the definition of variables