Writing code convention JS / React?

Hi, again!
In the quest to understand syntax better, a quick question.
In the example underneath, from codecademy, the function calculating the prime number is underneath the counter function reusing the prime function. In my mind it would make more sense to place the prime function above the counter function since counter uses prime. So why is it underneath? Is this a JS / React convention?

import React, { useState, useEffect } from 'react';

export const Counter = () => {

    const [counter, setCounter] = useState(0);

    useEffect(() => {
        if (isPrime(counter)) {
            document.body.style.backgroundImage = 'linear-gradient(to right, coral, teal)';
        } else {
            document.body.style.backgroundImage = "";
        }
    }, [counter]);

    return (
        <div>
            <h2>Count: {counter}</h2>
            <button onClick={() => setCounter(counter + 1)}>Click Me!</button>
        </div>
    );
};


const isPrime = (num) => {
    const squareRoot = Math.sqrt(num)
    for (let i = 2; i <= squareRoot; i++) {
        if (num % i === 0) {
            return false;
        }
    }
    return num > 1;
};
Was this page helpful?