View generateRandomString.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { customAlphabet, nanoid } from 'nanoid'; | |
import nanoidDictionary from 'nanoid-dictionary'; | |
export enum NanoidStringEnum { | |
NUMERIC = 'NUMERIC', | |
LOWERCASE = 'LOWERCASE', | |
UPPERCASE = 'UPPERCASE', | |
ALPHABETS = 'ALPHABETS', | |
ALPHANUMERIC = 'ALPHANUMERIC', | |
LOWERCASE_NUMERIC = 'LOWERCASE_NUMERIC', |
View index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let data; | |
let currentPage = -1; | |
let currentArticle = 0; | |
let loaderElement, articleContainer; | |
let totalPages; | |
const toggleLoader = () => { | |
if (loaderElement.classList.contains('hidden')) { | |
loaderElement.classList.remove('hidden'); | |
} else { |
View code-for-using-useState-in-axios-React.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useEffect, useState } from 'react'; | |
import axios from 'axios'; | |
const App = () => { | |
let [list, setList] = useState(<>LOADING</>); | |
useEffect(() => { | |
// You can use your link here | |
// I have created corsenabled.herokuapp.com just to bypass the CORS issue. It's only for testing and educational purpose only. No intention to infringe any copyrights or other legal matters |
View without-strict-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ction f1() { | |
return this; | |
} | |
// In a browser: | |
f1() === window; // true | |
// In Node: | |
f1() === globalThis; // true |
View strict-mode.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; // see strict mode | |
function f2() { | |
// 'use strict'; or else here | |
return this; | |
} | |
console.log(f2() === undefined) // true |
View call-apply-method.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// An object can be passed as the first argument to call or apply and this will be bound to it. | |
var obj = {a: 'Custom'}; | |
// We declare a variable and the variable is assigned to the global window as its property. | |
var a = 'Global'; | |
function whatsThis() { | |
return this.a; // The value of this is dependent on how the function is called | |
} |
View bind-method.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function f() { | |
return this.a; | |
} | |
var g = f.bind({a: 'azerty'}); | |
console.log(g()); // azerty | |
var h = g.bind({a: 'yoo'}); // bind only works once! | |
console.log(h()); // azerty |
View getter-setter.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sum() { | |
return this.a + this.b + this.c; | |
} | |
var o = { | |
a: 1, | |
b: 2, | |
c: 3, | |
get average() { | |
return (this.a + this.b + this.c) / 3; |
View Solution.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle { | |
constructor(w, h) { | |
this.w = w; | |
this.h = h; | |
} | |
} | |
/* | |
* Write code that adds an 'area' method to the Rectangle class' prototype | |
*/ |
View Problematic-Code.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Rectangle { | |
constructor(w, h) { | |
this.w = w; | |
this.h = h; | |
} | |
} | |
/* | |
* Write code that adds an 'area' method to the Rectangle class' prototype | |
*/ |
NewerOlder