Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                
              
            
!

CSS

              
                
              
            
!

JS

              
                
//String.matchAll 
//Performs a regular expression match of the String representing the this value against regexp and returns an iterator. Each iteration result's value is an Array object containing the results of the match, or null if the String did not match.
// https://262.ecma-international.org/11.0/#sec-string.prototype.matchall

const regex = /title: ([a-zA-Z]+)/g; //find everything matching 'title: ' then letters
const text = 'title: Doctor Aubrey Schivers title: Mr. Ted Nugent title: Honorable Barry Manilow';

console.log('String.matchAll Example');
[...text.matchAll(regex)].forEach(m => {
  console.log(m);
});

//BigInt
//A new number primitive for working with arbitrary precision integers;It can hold substantially bigger numbers than the standard Number type (whose limit is 2ˆ53, represented by the Number.MAX_SAFE_INTEGER constant.This limit depends on each implementation enviroment. 
// https://262.ecma-international.org/11.0/#sec-ecmascript-language-types-bigint-type

//BigInt number by appending a n
// Can be represented as 21654976586765468794645n or BigInt('21654976586765468794645')
//or directly initialize
console.log('BigInt Example')
const bigIntNumber = BigInt('17265892712658927912712189129121727918');
console.log(typeof bigIntNumber); //Outputs => bigint
//You can’t mix BigInts and numbers
 

//globalThis
//A universal way to access the global this value;  In  the browser, global is window. Node.js calls it global. Web workers, call it self. ECMAScript 2020 makes it easier to access this object by providing a globalThis variable:
// https://262.ecma-international.org/11.0/#sec-globalthis 

// In the browser
console.log('globalThis Example')
console.log(globalThis === window); // => true

// In Node.js
//console.log(globalThis === global); // => true

// In a web worker
//console.log(globalThis === self); // => true



//Promise.allSettled: 
//A new Promise combinator that does not short-circuit;The allSettled function returns a promise that is fulfilled with an array of promise state snapshots, but only after all the original promises have settled, i.e. become either fulfilled or rejected. It resolves all elements of the passed iterable to promises as it runs this algorithm. The result of B will be an array containing the results of all promises in A. Promise.allSettled is very similar to Promise.all, but the Promise.all fails if some of the supplied promises is rejected, while Promise.allSettled resolves no matter what.
// https://262.ecma-international.org/11.0/#sec-promise.allsettled 

const myPromiseA = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('foo');
    reject('nooo');
  }, 300);
});

const myPromiseB = new Promise((resolve, reject) => {
  setTimeout(() => {
    resolve('foo');
    reject('nooo');
  }, 1300);
});
//Takes an array of Promises
const roles =  Promise.allSettled([myPromiseA, myPromiseB]);
roles.then((r) => {
  console.log('Promise.allSettled Example')
  console.log(r)
})

//Nullish coalescing, a value selection operator; usage is identical to the OR operator but it only defaults to the second operand in case the first one is null or undefined
// https://262.ecma-international.org/11.0/#prod-CoalesceExpression  

console.log('Nulllish Coalescing Example');
//Instead of const pageTitle = title || 'No Page Title';
const title = null; //Set to '' empty string to see it return the empty value rather than the default
const pageTitle = title ?? 'No Page Title'; //ONLY defaults if titel is null or undefined 
console.log(pageTitle); //Outputs 'No Page Title' default value


//Optional chaining, a property access and function invocation operator that short-circuits if the value to access/invoke is nullish.
// Uses the nullish ? operator similar to typescript to identify props that may not be defined and returns undefined instead of error.
// https://262.ecma-international.org/11.0/#prod-OptionalChain 

console.log('Optional Chaining Example');

const obj = {};
//console.log(someObj.nonExistentProp1.nonExistentProp2.nonExistentProp3); //Uncaught TypeError: Cannot read properties of undefined (reading 'nonExistentProp2') 
console.log(obj?.nonExistentProp1?.nonExistentProp2); // undefined

const nullFunc = null;
console.log(nullFunc?.()); // undefined

const objDifferent = {};
console.log(objDifferent.nonExistentFunction?.()); // undefined

const nonArray = null;
console.log(nonArray?.[10]); // undefined




              
            
!
999px

Console