How to convert decimal to octal in JavaScript ?

Last Updated : 12 Jan, 2023

In this article, we are given a number and the task is to convert the number from decimal to octal. This can be done by using number.toString(8) method. It takes the parameter which is the base of the converted string. In this case, the base will be 8.

Syntax:

`number.toString(8)`

The below examples show the conversion from decimal to octal.

Example 1: In this example, we will convert 34 and 24680 into octal numbers.

javascript

 ``

Output:

```a = 42
b = 60150```

Example 2: In this example, we will convert some numbers into octal numbers.

javascript

 ``

Output:

```24
156725
501```

Example 3: In this example, we will apply onclick function to convert some numbers into octal numbers.

javascript

 ` ` `    ``

` `        ``GeeksForGeeks ` `    ``

` `    ``

` `        ``Convert to octal ` `    ``

` ` `  `    ``

` ` `  ` `  `    `` ` ` `  `    ``

` ` `  ` `  `    `` ` ``

Output:

Convert decimal to octal