The Battery Status API provides information about the system's battery charge level and lets you be notified by events sent when the battery level or charging status changes.
Knowing a device's battery status can be helpful in several situations or use cases. Here are some examples:
Let's take a look at a simple example to get the device's battery status:
navigator.getBattery().then((battery) => {
console.log(`Battery level: ${Math.round(battery.level * 100)}%`)
// Battery level: 57%
console.log(`Battery discharging time: ${battery.dischargingTime / 60} minutes`)
// Battery discharging time: 179 minutes
})
