What is the best way to initialize a JavaScript number?

The best way to initialize a number in JavaScript is to initialize variables while declaring them. Through this, you can easily avoid undefined values.


You can try to run the following code to initialize a number −

Live Demo

<!DOCTYPE html>
         var deptNum = 20, id = 005;
         document.write("Department number: "+deptNum);