Integer
String
Object
xxxxxxxxxx
Integer
String
Object
xxxxxxxxxx
var length = 16; // Integer
var lastName = "Johnson"; // String
var x = {
firstName: "John",
lastName: "Doe"
}; // Object
xxxxxxxxxx
// Example usage for: Null Coalesce Operator
$action = $_POST['action'] ?? 'default';
// The above is identical to this if/else statement
if (isset($_POST['action'])) {
$action = $_POST['action'];
} else {
$action = 'default';
}
xxxxxxxxxx
<?php
var_dump(5 ?: 0); // 5
var_dump(false ?: 0); // 0
var_dump(null ?: 'foo'); // 'foo'
var_dump(true ?: 123); // true
var_dump('rock' ?: 'roll'); // 'rock'
?>
xxxxxxxxxx
// Example usage for: Ternary Operator
$action = $_POST['action'] ?: 'default';
// The above is identical to this if/else statement
if (empty($_POST['action'])) {
$action = 'default';
} else {
$action = $_POST['action'];
}
xxxxxxxxxx
<?php
echo "Hello world";
// ... more code
echo "Last statement";
// the script ends here with no PHP closing tag
Integer
String
Object
xxxxxxxxxx
var length = 16; //
var lastName = "Johnson"; //
var x = {
firstName: "John",
lastName: "Doe"
}; //
function myFunction() {
return "Hello";
};
xxxxxxxxxx
function myFunction() {
return "Hello";
}
document.getElementById("demo").innerHTML = myFunction();
function myFunction() {
alert("Hello World!");
};
xxxxxxxxxx
alert("Hello World!");