Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

230
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda