sorry I know I often don’t word my questions well But here I go.
I am having trouble remembering what the exclamation point ( ! ) means. I think I recall it used like this.
!=
is strictly not equal
But in the third challenge of Basic Algorithm Scripting it says " Factorials are often represented with the shorthand notation n!
and the example is : 5! = 1 * 2 * 3 * 4 * 5 = 120
dose the exclamation point mean that five dose not equal 1 * 2 * 3 * 4 * 5 = 120
.or what is the meaning or reason for the exclamation point.
Thank you, Gabe.
In Javascript (and most programming languages), !
is the negation operator. !=
is “not equal to”. !true
is “false”. In math, !
is shorthand for “factorial”.
So !
is simply read as ‘not’ in javascript. It specifically switches a “true” value to a “false” one.
But yes, in print (in mathematics), the exclamation point is used to denote a factorial. So in the case of 5!
, it simply means 5! == 5*4*3*2*1
.
Note that, in javascript, the above line will do all kinds of weird things. It will assume the exclamation is a inverse
operator, and attempt to do something… I can’t even guess what.
Great, thank you very much.
Thank you very much. again you have been a great help:smiley:
In this case you’ll end up with a syntax error. The Logical NOT operator should precede what it’s meant to negate, and a space isn’t a legal character for it to precede.
Now, if you changed up the spacing just a bit and evaluated 5 !== 5*4*3*2*1
, it’ll return as true.
Alternatively, if you swapped the order around and evaluated !5
, it would evaluate as false. This is because non-zero integers in JS are truthy. And you’d just be negating that truthy with the NOT operator.
Yeah, I just had nowhere near enough coffee in me yet.
Well said, though, and exactly right.