Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

229
Views
Why is the Bitwise OR operator being used in a variable declaration?

I'm learning Angular and reading through the documentation but I'm confused why the bitwise OR operator is being used in the product variable declaration below. What does the product: Product | undefined line mean?

export class ProductDetailsComponent implements OnInit {

  product: Product | undefined;
  /* ... */
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In that context it is not the OR operator but a "Union Type".

In TypeScript, a union type variable is a variable which can store multiple type of values (i.e. number, string etc).

A union type allows us to define a variable with multiple types. The union type variables are defined using the pipe ('|') symbol between the types.

Source: https://howtodoinjava.com/typescript/union-types/

So this means that product must be of type Product or undefined. (the undefined part is only relevant if you have strictNullChecks enabled).

Another way to write this is

product?: Product;

Where the question mark indicates that it is an optional parameter.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!