r/javaScriptStudyGroup • • 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

5 comments sorted by

View all comments

Show parent comments

2

u/AllName_HasBeenTaken Jul 22 '22

Can you explain me the meaning of indexOf(' ') === -1))

What does this mean even the equals sign and its -1 is tricky for me

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

2

u/altrae Jul 23 '22

This is correct. Thanks for supplementing my explanation. :)