Write an efficient program to print prime numbers.

What is a prime number?

Prime numbers are numbers that are greater than 1 and it has only two factors, 1 and the number itself.

The solution to print prime number:

Following is the code to write prime number up to 20 in JavaScript.

    for(let i = 2; i < 20; i++){
        for(let j = 2; j <= i; j++) {
            if(i % j === 0 && j !== i){
                break;
            }

            if (i === j) {
                console.log(i);
            }
        }
    }