Could you give some explanation on how is if (checkAge(age)) is a condition?
A simple age checking function:
function checkAge(age) {
if (age >= 18) {
return true;
} else {
return confirm('Do you have permission from your parents?');
}
}
let age = prompt('How old are you?', 18);
if ( checkAge(age) ) {
alert( 'Access granted' );
} else {
alert( 'Access denied' );
}
Does that mean the function become "true" if meet either requirement (>=18 or confirmed)?
Why the if statement below can execute when I just put a true value in it? (i.e. IF(1) )
Is the ok to write if(checkAge(age) == true)? If not, why?
Also which part of the code called the function? the lower if statement?
Sorry as I am a beginner and just wanna get a clear vision of the logic.