我无法理解 IF 参数中 RETURN 指令的这种特定语法

I cannot understand this specific syntax of the RETURN instruction within the IF argument

我正在通过一些练习来学习 JS。其中之一是关于编写一个函数来检查数字是否为质数。本练习的正确答案是:

const isPrime = num => {
  for(let i = 2; i < num; i++)
    if(num % i === 0) return false;
  return num > 1;
}

我习惯于在 if 参数内插入 return false; 并在其外插入 return num > 1;return true;,就在结束 [ 的右括号之后=13=] 参数,与 if 语句一样,我通常会告诉我的函数“如果这个条件满足,return 这个”并且在关闭之后我告诉它的 if 语句“...否则 return 那 ”。我不明白为什么在这种情况下 return 指令都被插入到参数中,这背后的逻辑是什么?

这个

const isPrime = num => {
  for(let i = 2; i < num; i++)
    if(num % i === 0) return false;
  return num > 1;
}

等同于

const isPrime = num => {
    for(let i = 2; i < num; i++){
        if(num % i === 0){
            return false;
        }
    }
    return num > 1;
}

Explanation

代码块通常用花括号括起来{ code }。因此,当代码的某些部分需要在 for 循环内或在 if 条件之后执行时,我们将其括在花括号中。但是,如果在if之后或者for循环里面只有一条语句需要执行,我们就可以不用大括号了。如果 condition/for 循环属于它,代码会考虑紧接着的下一行。

//if
if(condtion){
    console.log("hello world");
}
//for
for(let i=0;i<num;i++){
    console.log(i);
}

//also equals to 
if(condition)
    console.log("hello world");
//for
for(let i=0;i<num;i++)
    console.log(i);