Brackets are necessary for the multi-line style I used here, and in single-line style when you have more than one expression in a branch. Style guides (including the tidyverse style guide) often recommend defaulting to using brackets and multiple lines, and only using a single-line, no-bracket style if your statement is very simple.
ifelse is a function for conditional selection of elements. Roughly speaking, it returns a new object that is meant to have all the properties of the one you tested, except with element values chosen based on the outcome of the test. The dplyr version, if_else, is more strict about data types, and therefore has more predictable output.