How to convert Celsius to Fahrenheit in JavaScript

The two most often used temperature scales are as follows:

  • Fahrenheit
  • Celsius

Celsius vs. Fahrenheit

Celsius is the world’s most widely used temperature scale, commonly known as Centigrade and written as °C. Celsius is most widely used in scientific and medical applications because it is simpler to work with. Fahrenheit (written as °F) is still commonly used in many everyday applications in the United States.

Celsius to Fahrenheit conversion formula

We can convert the temperature from Celsius to Fahrenheit using the formula below.

F=(C×95)+32F = \left(C \times \frac{9}{5} \right) + 32

where, FF is the Fahrenheit temperature, and CC is the Celsius temperature.

Problem statement

We are given a temperature value and need to convert that temperature to Fahrenheit using the above formula.

Explanation

Let’s suppose we have a temperature of 5050 degrees Celsius. Putting the value of CC in the above formula,

Given, C=50°CC = 50\degree C.

F=(C×95)+32=(50×95)+32=(50×1.8)+32=90+32=122°F\begin{split} F & = \left(C \times \frac{9}{5} \right) + 32 \\ & = \left(50 \times \frac{9}{5} \right) + 32 \\ & = (50 \times 1.8) + 32 \\ & = 90 + 32 \\ & = 122 \degree F \end{split}

Implementation

Let’s see an example of converting the temperature of Celsius to Fahrenheit in JavaScript:

let c = 50;
let f = 0;
// Using the above formula
f = (c * (9 / 5)) + 32;
console.log("The value of the temperature in Fahrenheit is " + f);

Code explanation

  • Lines 1–2: We initialize variables c and f with values 50 and 0, respectively.
  • Line 5: We use the formula to calculate the value of f.
  • Line 6: We print the value of f to the console.

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved