JavaScript. Loops, conditions.

Home » Tutorials » JavaScript » JavaScript. Loops, conditions.
In this lesson we’ll consider important themes in javascript and programming in general – conditions, loops, break and much more. In the beginning we will discuss unary plus and minus. You must notice several key features.
  1. unary plus has got the highest priority comparing binary plus.
  2. unary plus turn strings to a number. For example “7”
    will be 7.
  3. If there is addition of two numbers (binary plus), we can say it is traditional mathematical addition. But if on of the operand is string,
    it will be concatenation of strings.
Also I considered logical operations: and (&&), or (||), not (!)

Code lesson (js)

var a = "5";
var b = "7";

//alert(a+b);

/* Порядок выполнения операций
1.a->5
2. b->7
3. a+b
*/
//alert(+a + +b);

//alert(2-"3"); // - 1

//var str = "Камиль " + "Абзалов";
//alert(str);

/*var c = 49;

if (c>50) {
	console.log("Значение больше 50");
} else if(c == 50){
	console.log("Значение равно 50");
} else {
	console.log("Значение меньше 50");
}

var d = 4;
var e = 2;

//Краткая запись if-else
//var f = (d>e) ? d : e;
//console.log(f);

/*|| -> +
&& -> **/

//console.log(1&&1); 

/*
true->1
false->0
*/

//alert(!4);

//var num = 12;

/*while(num>=0) {
	console.log(num);
	num--;
}*/

/*do {
	console.log(num);
	num--;
}while(num>10)*/

/*for(var i=0; i<10; i++) {
	//if(i==6) break;
	if(i==6) continue;
	//console.log(i);
}

var c = 5;
var d = 9;
var e = c+d;

switch(e) {
	case 11:
	case 13:
		console.log("Это не то, что мы ожидали ");
		break;
	case 12:
		console.log("Это то, что мы ожидали");
		break;
	default:
		console.log("Действие по умолчанию");
	        break;
}*/

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *


The reCAPTCHA verification period has expired. Please reload the page.

Pin It on Pinterest

Share This