Forma e përgjithshme e shkurtër e kontrollit në JavaScript

Forma e shkurtër e kontrollit funksionon edhe për llojet e tjera të të dhënave. Në këtë rast këto të dhëna fillimisht shndërrohen në tipin boolean, dhe pastaj krahasohen me true. Shihni shembullin:

javascriptlet test = 3;

if (test) {
  console.log('+++'); // do të ekzekutohet kjo
} else {
  console.log('---');
}

Në fakt kodi i paraqitur është ekuivalent i kësaj:

javascriptlet test = 3;

if (Boolean(test) === true) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 1

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = 3;

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 2

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = 'abc';

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 3

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = '';

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 4

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = 3 * 'abc';

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 5

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = null;

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 6

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = false;

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 7

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test;

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 8

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = 0;

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 9

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = '0';

if (test) {
  console.log('+++');
} else {
  console.log('---');
}
Задание 10

Pa ekzekutuar kodin, përcaktoni se çfarë do të shfaqet në konsol:

javascriptlet test = -1;

if (test) {
  console.log('+++');
} else {
  console.log('---');
}