Skip to content

Instantly share code, notes, and snippets.

View cihat's full-sized avatar
💻
writing code🚀

Cihat SALİK cihat

💻
writing code🚀
View GitHub Profile
In most cases, the in operator is the best way to determine whether
the property exists in an object. It has the added benefit of not evaluating the value of the property, which can be important if such an evaluation is likely to cause a performance issue or an error.
In some cases, however, you might want to check for the existence of
a property only if it is an own property. The in operator checks for both
own properties and prototype properties, so you’ll need to take a different
approach. Enter the hasOwnProperty() method, which is present on all objects
and returns true only if the given property exists and is an own property.
For example, the following code compares the results of using in versus
hasOwnProperty() on different properties in person1:
Removing Properties
Just as properties can be added to objects at any time, they can also be
removed. Simply setting a property to null doesn’t actually remove the
property completely from the object, though. Such an operation calls
[[Set]] with a value of null, which, as you saw earlier in the chapter, only
replaces the value of the property. You need to use the delete operator to
completely remove a property from an object.
The delete operator works on a single object property and calls an
internal operation named [[Delete]]. You can think of this operation as
removing a key/value pair from a hash table. When the delete operator is
Types of Properties
There are two different types of properties: data properties and accessor
properties. Data properties contain a value, like the name property from earlier examples in this chapter.
The default behavior of the [[Put]] method
is to create a data property, and every example up to this point in the
chapter has used data properties. Accessor properties don’t contain a value
but instead define a function to call when the property is read (called
a getter), and a function to call when the property is written to (called a
setter). Accessor properties only require either a getter or a setter, though
they can have both.
@cihat
cihat / essential-javascript-links.md
Created December 6, 2020 00:10 — forked from ericelliott/essential-javascript-links.md
Essential JavaScript Links
@cihat
cihat / Making AJAX calls in pure JavaScript
Created February 1, 2021 12:33
Making AJAX calls in pure JavaScript
const getCountryData = country => {
const request = new XMLHttpRequest();
request.open('GET', `https://restcountries.eu/rest/v2/name/${country}`);
request.send();
request.addEventListener('load', function () {
const [data] = JSON.parse(this.responseText);
console.log(data);
countriesContainer.insertAdjacentHTML('beforeend', html);
countriesContainer.style.opacity = 1;
@cihat
cihat / branch conflict
Created April 30, 2021 10:12
branch conflict
git add -A
git stash
git checkout master
git pull origin master
git checkout development(branch)
{
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"semi": false,
"singleQuote": true,
"trailingComma":"none",
"bracketSpacing": true,
"jsxBracketSameLine": false
}
@cihat
cihat / vs-code-user-setting.md
Created May 25, 2021 10:18 — forked from xgqfrms-GitHub/vs-code-user-setting.md
VS code setting.json & React JS
* {
padding: 0;
margin: 0;
list-style: none;
border: none;
text-decoration: none;
box-sizing: border-box;
-webkit-overflow-scrolling: touch;
}
@cihat
cihat / iterm2.md
Created June 6, 2021 12:56 — forked from squarism/iterm2.md
iterm2 cheatsheet

Tabs and Windows

Function Shortcut
New Tab + T
Close Tab or Window + W (same as many mac apps)
Go to Tab + Number Key (ie: ⌘2 is 2nd tab)
Go to Split Pane by Direction + Option + Arrow Key
Cycle iTerm Windows + backtick (true of all mac apps and works with desktops/mission control)