I was trying to add some form validation to a simple form I was working on earlier and I wrote the following snippet
if (!lesson.title && lesson.title.trim().length == 0) throw Error("Kindly provide a lesson title");
Then it occurred to me to try something unconventional, instead of the logic "length EQUALS zero", I wanted to try "length NOT EQUAL TO OR LESS THAN zero", then I came up with the following snippet
if (!lesson.title && lesson.title.trim().length <=! 0) throw Error("Kindly provide a lesson title");
To my surprise, I worked, but I didn't really understand the logic behind that so I tried out a couple of assertions with the outcomes:
"s".length <=! 0 // TRUE
"sm".length <=! 0 // FALSE
"s".length =! 0 || "s".length < 0 // TRUE
"s".length =! 0 && "s".length < 0 // FALSE
"sm".length =! 0 && "sm".length < 0 // FALSE
"sm".length =! 0 || "sm".length < 0 // TRUE
Can someone kindly explain to me what is going on here? I'm confused.