Battery API

Get battery status

IntermediateTopic: Browser API
Back

JavaScript Battery API Program

This program helps you to learn the fundamental structure and syntax of JavaScript programming.

Try This Code
navigator.getBattery().then(battery => {
    console.log('Level:', battery.level);
    console.log('Charging:', battery.charging);
});
Output
Level: 0.85
Charging: true

Understanding Battery API

Battery API provides battery information.

Note: To write and run JavaScript programs, you need to set up the local environment on your computer. Refer to the complete article Setting up JavaScript Development Environment. If you do not want to set up the local environment on your computer, you can also use online IDE to write and run your JavaScript programs.

Table of Contents