return stop function javascript code example
Example 1: js break out of a function
By using 'return;':
function myfunction(){
if(a == 'stop')
return;
}
Does not work when using a Conditional operator:
let result = 1 == 2 ? "YES" : return;
Example 2: stop a function javascript
function func() {
if (conditionToStopFunction)
return;
console.log("Hello World");
}
Example 3: c# stop loop in method
class MainClass {
public static void Main (string[] args) {
UnlockDoor();
PickUpSword();
}
static bool UnlockDoor()
{
bool doorIsLocked = true;
while (doorIsLocked)
{
bool keyFound = TryKey();
if (keyFound)
{
return true;
}
}
return false;
}
}