×
Clear all filters including search bar
Valeri Tandilashvili's Personal Professional Blog
let numbers = [10, 100, 1000]
let doubled = numbers.map(function(x){
return x * 2
})
document.write(doubled)
Alternative arrow function:let doubled = numbers.map((x) => { return x * 2 })
If it's only a single line we don't need curly brackets and the keyword return
let doubled = numbers.map((x) => x * 2);
If the arrow function has only one parameter, it does not need parentheses:let doubled = numbers.map(x => x * 2);
Note: We only need parentheses
if we had zero or more than one parametersSELF JOIN
SELECT
s1.*,
s2.first_name
FROM `students` s1
JOIN `students` s2 ON s2.santa_id = s1.id
This type of join is often used when we have tree structure in a table.
Note: alias
is mandatory in SELF JOIN
alias
to tables or table columns.
In this example table column first_name
will be displayed as student_name
SELECT
id,
first_name AS student_name
FROM students
The keyword AS
is optional, but it's better to use it, because the query is much more readable.
The following query returns the same resultSELECT
id,
first_name student_name
FROM students
We can use alias
in ORDER BY
clause to order the resultSELECT *, price * quantity AS total
FROM `orders`
ORDER BY total DESC
If alias
is given to table, column of the table can be accessed by the alias followed by .
SELECT
s.id,
s.first_name
FROM `students` s
In SELF JOIN
alias is required, because MySQL needs to treat the tables as different tablesSELECT
s1.*,
s2.first_name
FROM `students` s1
JOIN `students` s2 ON s2.santa_id = s1.id
quotes
or backticks can be used in alias.
Possible options: single quote '
, double quote "
or backtick `
SELECT
id,
first_name AS 'student_name'
FROM
students
Advantage of using quotes
is that we can use space separated names in aliasSELECT
first_name,
last_name,
(points + 10) * 2 AS 'points calculated'
FROM students
$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5);
// Returns the JSON representation of a value (pretty printed)
echo json_encode($arr, JSON_PRETTY_PRINT);
Result of the above code{
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5
}
The following example shows how the PHP objects can be converted into JSONclass Emp {
public $name = "";
public $hobbies = [];
public $birthdate = "";
}
$e = new Emp();
$e->name = "sachin";
$e->hobbies = ["sport", "reading"];
$e->birthdate = date('Y-m-d', strtotime('2015-11-18'));
echo json_encode($e);
The above code will produce the following result{"name":"sachin","hobbies":["sport","reading"],"birthdate":"2015-11-18"}
Decoding JSON in PHP (json_decode)
The following example shows how PHP can be used to decode JSON objects$json = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
// Decoding into an object
var_dump(json_decode($json));
// Decoding into an array
var_dump(json_decode($json, true));
While executing, it will produce the following resultobject(stdClass)#1 (5) {
["a"]=> int(1)
["b"]=> int(2)
["c"]=> int(3)
["d"]=> int(4)
["e"]=> int(5)
}
array(5) {
["a"]=> int(1)
["b"]=> int(2)
["c"]=> int(3)
["d"]=> int(4)
["e"]=> int(5)
}
1. XML Syntactical whitespace - is whitespace required by the XML in order to delimitate XML constructs.
2. Insignificant Whitespace - is whitespace, that is not considered part of an element, if two elements are separated by just whitespace its considered insignificant.
3. Significant Whitespace - is whitespace that XML element attribute contains.
this
inside driveCar()
function refers to the global window object.
Global variables firstName
and lastName
are added to the window
object.
That is why they are visible using the keywordfirstName = "Jack"
lastName = "Ma"
function driveCar() {
document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}
driveCar()
If we call the same function using call
function, this
will refer to the object that will be passed.
In this case: john
objectlet john = {
firstName: 'John',
lastName: 'Doe'
}
function driveCar() {
document.write(this.firstName + ' ' + this.lastName + ' is driving a car<br/>')
}
driveCar.call(john)
- Comment must appear after XML declaration.
- Comment may appear anywhere in a document
- Comment must not appear within attribute values.
- Comment cannot be nested inside the other comment.
true
but in PHP it evaluates to false
if ("0") {
}
.mt-3
- margin-top
.mr-3
- margin-right
.mb-3
- margin-bottom
.ml-3
- margin-left
.mx-3
- margin-left, margin-right
.my-3
- margin-top, margin-bottom
.m-3
- margin-top, margin-bottom, margin-left, margin-right
The same for padding properties:
.pt-3
- padding-top
.pr-3
- padding-right
.pb-3
- padding-bottom
.pl-3
- padding-left
.px-3
- padding-left, padding-right
.py-3
- padding-top, padding-bottom
.p-3
- padding-top, padding-bottom, padding-left, padding-rightvar text = '{ "name":"John", "age":"function () {return 30;}", "city":"New York"}';
var obj = JSON.parse(text);
obj.age = eval("(" + obj.age + ")");
document.getElementById("demo").innerHTML = obj.name + ", " + obj.age();