Sintaxis de la condición de Javascript

I'm trying to get a condition working but not sure about the syntax...

How would I write this in jquery/javascript?

if (value.type) == 'football' then {
 //do something
} else {
  //do something else
}

preguntado el 28 de agosto de 12 a las 12:08

3 Respuestas

if (value.type == 'football') {
    //do something
} else {
    //do something else
}

Referencia: if...else, == vs ===.

contestado el 23 de mayo de 17 a las 13:05

if ((value.type) == 'football') {
 //do something
} 
else {
  //do something else
}

or

if (condition) {
 //do something
} 
else if(condition) {
  //do something else
}
else {
  //do something else
}

Respondido 28 ago 12, 12:08

JS

if (value.type === 'football')
{
    //Do something
}
else
{
    //Do something else
}

or you could use the short if

message = ('value.type' === 'football') ? "type is equal to football" : "type is not equal to football";

jQuery is just a js library and it doesn't have if else implementation cause it really not needed.

Espero eso ayude

Respondido 28 ago 12, 12:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.