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.

Example

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

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <script>
         var deptNum = 20, id = 005;
         document.write("Department number: "+deptNum);
      </script>
   </body>
</html>
Updated on: 2020-06-17T06:38:06+05:30

678 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements