Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

191
Vistas
variable initializing problem with "getFirestore" in javascript while using Firebase
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-app.js";
import { getAnalytics } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-analytics.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.6.6/firebase-firestore.js";

const firebaseConfig = {
  apiKey: "AIzaSyBqHAqkn8hCZt8WVsot9eg7ifzycgV1Acw",
  authDomain: "to-do-list-3ee68.firebaseapp.com",
  databaseURL: "https://to-do-list-3ee68-default-rtdb.firebaseio.com",
  projectId: "to-do-list-3ee68",
  storageBucket: "to-do-list-3ee68.appspot.com",
  messagingSenderId: "362512451257",
  appId: "1:362512451257:web:24f5b612c55a163b01bd68",
  measurementId: "G-CG8HCTLWY6"
};

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const analytics = getAnalytics(app);
const db = getFirestore();
</script>

<script src="./script.js"></script>

this is cdn of firebase and i made script.js file like below.

 function addItem(event){
 event.preventDefault();
 let text=document.getElementById("todo-input");
 db.collection("todo-items").add({
   text: text.value,
   status: "active"
  });
}

but i got an error like this. i want to know why i can't use the variable "db".

Uncaught ReferenceError: db is not defined at addItem (script.js:4:3) at HTMLFormElement.onsubmit (index.html:56:41)

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda