Company logo
  • Empleos
  • Bootcamp
  • Acerca de nosotros
  • Para profesionales
    • Inicio
    • Empleos
    • Cursos y retos
    • Preguntas
    • Profesores
    • Bootcamp
  • Para empresas
    • Inicio
    • Nuestro proceso
    • Planes
    • Pruebas
    • Nómina
    • Blog
    • Calculadora

0

72
Vistas
How can I replace ?? with ternary operator in js?

I have a JS file which was created using browserify, and it uses the ?? operator. The problem is, the environment where I am executing this JS file doesn't support that operator yet.

Is there any way I can go through the file, search and replace it using regex?

The change would be from this:

object.error ?? 0

To this:

x == undefined ? 0 : object.error
6 months ago · Santiago Gelvez
1 Respuestas
Responde la pregunta

0

Is it JS or Python?

Anyway, try capturing the line with:

(([^ \t]+)[ \t]*\?\?[ \t]*\d+)

This expression returns two groups:

  1. The line to be replaced
  2. The object.error

You then need to replace group#1 by x == undefined ? 0 : group#2

6 months ago · Santiago Gelvez Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar empleo Planes Nuestro proceso Comercial
Legal
Términos y condiciones Política de privacidad
© 2023 PeakU Inc. All Rights Reserved.