Tutorialspoint

ES6 Variables Example

var num1 = 5; 
var num2 = 9; 

console.log("Value of num1: " + num1); 
console.log("Value of num2: " + num2); 

var res = num1 > num2; 
console.log("num1 greater than num2: " + res); 

res = num1 < num2; 
console.log("num1 lesser than num2: " + res); 

res = num1 >= num2; 
console.log("num1 greater than or equal to  num2: " + res); 

res = num1 <= num2; 
console.log("num1 lesser than or equal to num2: " + res); 

res = num1 == num2; 
console.log("num1 is equal to num2: " + res); 

res = num1 != num2; 
console.log("num1 not equal to  num2: " + res);

ES6 Arithmetic Operators Example

var num1 = 10 
var num2 = 2 
var res = 0 

res = num1+num2 
console.log("Sum:        "+res); 

res = num1-num2; 
console.log("Difference: "+res) 

res = num1*num2 
console.log("Product:    "+res) 

res = num1/num2 
console.log("Quotient:   "+res) 

res = num1%num2 
console.log("Remainder:  "+res) 

num1++ 
console.log("Value of num1 after increment "+num1) 

num2-- 
console.log("Value of num2 after decrement "+num2) 

ES6 Variables Example

var main = function() { 
   for(var x = 0;x<5;x++) { 
      console.log(x); 
   } 
   console.log("x can be accessed outside the block scope x value is :"+x); 
   console.log('x is hoisted to the function scope'); 
} 
main();

ES6 Global vs Local Variable

var num = 10 
function test() { 
   var num = 100 
   console.log("value of num in test() "+num) 
} 
console.log("value of num outside test() "+num) 
test()

ES6 Variables Example

var name = "Tom" 
console.log("The value in the variable is: "+name)

PHP7 Valid Return Type

php

<?php
   class A {
      function A() {
         print('Style Constructor');
      }
   }
?>

PHP7 Valid Return Type

php

<?php
   $value = intdiv(10,3);
   var_dump($value);
   print(" ");
   print($value);
?>

PHP7 Valid Return Type

php

<?php
   class MathOperations {
      protected $n = 10;

      // Try to get the Division by Zero error object and display as Exception
      public function doOperation(): string {
         try {
            $value = $this->n % 0;
            return $value;
         } catch (DivisionByZeroError $e) {
            return $e->getMessage();
         }
      }
   }

   $mathOperationsObj = new MathOperations();
   print($mathOperationsObj->doOperation());
?>

PHP7 Valid Return Type

php

<?php
   ini_set('assert.exception', 1);

   class CustomError extends AssertionError {}

   assert(false, new CustomError('Custom Error Message!'));
?>

PHP7 Valid Return Type

php

<?php
   print(random_int(100, 999));
   print("");
   print(random_int(-1000, 0));
?>

Advertisements
Loading...