Skip to content

Instantly share code, notes, and snippets.

View szaranger's full-sized avatar

Sean Amarasinghe szaranger

View GitHub Profile
const person = Object.create(null);
person.age = 21;
if (Object.hasOwn(person, 'age')) {
console.log(person.age); // true - works regardless of how the object was created
}
if (person.hasOwnProperty('age')){ // throws error - person.hasOwnProperty is not a function
console.log('hasOwnProperty: ', person.age);
}
const fruits = ['apples', 'oranges', 'pears'];
console.log(fruits[fruits.length - 1]); // pears
console.log(fruits.at(0)); // apples
console.log(fruits.at(-1)); // pears
class User {
username;
#address;
set #address(addr) {
#address = addr;
}
get #address() {
return #address;
class User {
username;
static userId;
static get userId() {
return userID;
}
}
class User {
username;
dateOfBirth;
#address;
get #address() {
return #address;
}
}
class User {
username;
dateOfBirth;
#address;
}
import { getUser } from './api/User';
const user = await getUser();
const res = await fetch('<https://swapi.dev/api/people/1/>');
const person = res.text();
nav {
/*column-count: 4;
column-width: 150px;*/
columns: 4 120px; /* same as above */
column-gap: 2rem;
column-rule: 1px dashed #ccc;
}
<section>
<h2>Europe</h2>
<nav>
<ul>
<li><a href="#">Belgium</a></li>
<li><a href="#">Netherlands</a></li>
<li><a href="#">Denmark</a></li>
<li><a href="#">Germany</a></li>
<li><a href="#">Czechia</a></li>
<li><a href="#">France</a></li>