Well, the use of the two points is basically employed in objects:
var frutas = {
"banana":{
cor: "yellow"
}
}
With the object you simply "navigate" between key levels:
frutas.banana.cor; // yellow
So whenever a key is used on an object, a value is assigned to it, by means of the two points :
, instead of the same =
, used for variables, in general.
In your example I believe a key is missing }
, but it must have been the glue...
function paciente(nome, idade, altura) {
var clazz = {
imprime: function() {
alert("nome: " + nome + ", idade: " + idade);
}
}
return clazz;
}
You have a function, you have an object, that object receives a key imprime
, this takes a function that returns a concatenation of the first two arguments of the function, i.e.:
paciente('João', 35, "1,80m").imprime() // João, 35
There are other uses, for example in conditional variables:
var cor = arguments.length > 0 ? arguments[0] : "black";
In the above example, coming out of the assumption that this code is within a function, you’re saying: if the number of arguments is greater than zero the variable "color" will be equal to the first argument, otherwise it will be equal to "black".
The "else"/"Else" is represented by the Colon (colon).
There are still the labels
, implemented with Ecmascript, look:
var i, j;
loop1:
for (i = 0; i < 3; i++) { // Primeira declaração rotulada "loop1"
loop2:
for (j = 0; j < 3; j++) { // Segunda declaração rotulada "loop2"
if (i === 1 && j === 1) {
continue loop1;
}
console.log("i = " + i + ", j = " + j);
}
}
You can use a label
to identify a loop, and then use the break or continue to indicate whether a program should interrupt the loop or continue with its implementation.
I left that last option only to the level of curiosity I almost never see subjects about these labels
, also not use with a lot of frequencies, but are very interesting, I recommend you see the links.
Thanks @Samir Braga
– Emanoel