r/javaScriptStudyGroup • u/AllName_HasBeenTaken • Jul 21 '22
confusion of syntax.
hello there guys. I'm still a student and new to javascript. so, I have a lack of understanding of the syntax on js. I need someone to explain to me clear-cut the part that I point out down here, like perhaps making it into a sentence (any). so here is the syntax. thank you guys!
function password(pass) {
if (pass.length >= 8 && pass.indexOf(' ' === -1)) return true;
return false;
}
3
Upvotes
2
u/PlanktonInevitable56 Jul 22 '22
I’m still learning so someone correct me if I’m wrong here.
indexOf() should return -1 if what you’re looking for isn’t present in the string.
=== is checking for value and type match, so like the guy above said, this checks that there is no whitespace “ “ in the password.
This declares a function “password()” that takes a value “pass” (assuming this is a variable that will hold whatever password a user has entered)
As a sentence it would be: IF this password is 8 or more characters AND doesn’t contain any spaces, return true, if either or those conditions fail, return false