Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

190
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!