Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialBoris Vukobrat
851 Points=== is not ternary operator
Ternary operators has three operands. Operator 'identical' ( === ) has two operands.
4 Answers
Steve Hunter
57,712 PointsI just had a look at the beginning of that video and it contradicts what I've been taught previously. I agree with you that an operator that takes a value either side of it is a binary operator. Like addition, +, this is a binary operator x + y, yet in the video it is called a unary operator. The thing that is being 'counted' is the number of operands so unary is something like NOT, or increment (++), decrement (--). These can be applied to a single operand - hence they are unary operators.
Binary operators require two operands, addition (as above), subtraction etc; they need two numbers (operands) to work on.
I'll be honest, I Googled a ternary operator as I couldn't think of one that takes three operands. There's a conditional operator, I found. It needs a condition and two outputs based on the true/false outcome of the condition - as such it is a ternary operator.
I agree with you that the beginning of this video, on the face of it, seems confusing/confused and may need a little extra clarity.
Steve.
Stephen Van Delinder
21,457 PointsI've always heard the ternary operator refer to ?: as a shorthand for if/else.
http://php.net/manual/en/language.operators.comparison.php
<?php
// Example usage for: Ternary Operator
$action = (empty($_POST['action'])) ? 'default' : $_POST['action'];
// The above is identical to this if/else statement
if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}
?>
Steve Hunter
57,712 PointsI agree - that's precisely what I was referring to. The conditional operator you give takes three parameters - the conditional part, the true outcome and the false outcome - hence it is ternary. The triple-equals is a binary operator as it takes two operands (the video says it is ternary) and the addition operator (+) is also binary as it takes two operands (again, the video is contrary to that, saying + is a unary operator).
Steve Hunter
57,712 PointsSome further posts on the same point: https://teamtreehouse.com/community/operators-4
https://teamtreehouse.com/community/php-basics-operators
I've emailed Support to flag it too.
Steve.
Steve Hunter
57,712 PointsThere's the correct definition of a ternary operator at around 7m28s in this video. Perhaps Craig Dennis can have the PHP course looked at to correct the incorrect definitions regarding unary, binary and ternary operators.
Craig Dennis
Treehouse TeacherThanks Steve! Alena Holligan and I will take a look!
Steve Hunter
57,712 PointsThank you, Craig. There are a few statements on the techy stuff regarding operators that aren't correct. It would be good to have those edited.
Steve.
Alena Holligan
Treehouse TeacherI had already updated the Teachers notes and it is on our list to update the videos.