What is the difference between using PHP and JavaScript for automatic calculations in a form?

When using PHP for automatic calculations in a form, the calculations are done on the server-side, meaning that the user will need to submit the form for the calculations to take place. On the other hand, using JavaScript allows for calculations to be done on the client-side, providing instant feedback to the user without needing to submit the form. PHP Code Snippet:

<?php
if(isset($_POST['submit'])){
    $num1 = $_POST['num1'];
    $num2 = $_POST['num2'];

    $result = $num1 + $num2;

    echo "Result: " . $result;
}
?>

<form method="post">
    <input type="text" name="num1" placeholder="Enter number 1">
    <input type="text" name="num2" placeholder="Enter number 2">
    <input type="submit" name="submit" value="Calculate">
</form>