var person = {
firstName: "Penelope",
lastName: "Barrymore",
fullName: function () {
// Notice "this" refers to an object
console.log(this.firstName + " " + this.lastName);
// We could have also written this:
console.log(person.firstName + " " + person.lastName);
}
}
console.log(school.hasOwnProperty ("schoolName")); // true because schoolName is an own property on the school object
// Prints false because the school object inherited the toString method from Object.prototype, therefore toString is not an own property of the school object.
console.log(school.hasOwnProperty ("toString"));
var school = {schoolName:"MIT"};
console.log("schoolName" in school); // true because schoolName is an own property on the school object
console.log("schoolType" in school); // false because because we did not define a schoolType property on the school object
// Prints true because the school object inherited the toString method from Object.prototype.
console.log("toString" in school); // true
var christmasList = {mike:"Book", jason:"sweater" }
then delete some property with delete keyword
delete christmasList.mike; // deletes the mike property
Configurable Attribute
: Specifies whether the property can be deleted or changed.
Enumerable
: Specifies whether the property can be returned in a for/in loop.
Writable:
Specifies whether the property can be changed.datetime
objects using createFromFormat
static method of DateTime
built-in class$first_date = DateTime::createFromFormat('Y-m-d', "2020-12-23");
$second_date = DateTime::createFromFormat('Y-m-d', "2020-12-30");
Using diff()
method of DateTime
class we actually calculate differences between the two dates and we get the result in days$difference_between_the_days = $second_date->diff($first_date)->format("%a");
echo $difference_between_the_days;
$Datetime_object = DateTime::createFromFormat('Y-m-d', "2020-12-23");
function hello() { alert('Hi there!'); }
setTimeout(hello, 5000)
or
setTimeout( function() { alert('Hi there!'); }, 5000 )
var family = ["mom", "dad", "mike", "jenny"]
var fstr = family.join();
output:
fstr = "mom,dad,mike,jenny"
var parents = ["mom", "dad"]
var children = ["mike", "jenny"]
var family = parents.concat(children);
Result of family variable:
["mom", "dad", "mike", "jenny"]