Today I Learned - Rocky Kev

TIL adding a debug flag for custom features

POSTED ON:

TAGS:

This is a cool way to turn on some debug tricks.

Adding ?debug flag to turn on a bunch of config options.


// website.com/?color=blue&debug=true
const urlParams = new URLSearchParams(window.location.search);
const pageType = urlParams.get('color')
const isDebug = urlParams.get('debug')

console.log(pageType); // blue
console.log(isDebug); // true

Then in your JS, you can:

You probably don't want to pass this code to production though.

And maybe it might be better to use (.env)[https://www.npmjs.com/package/dotenv].


Related TILs

Tagged:

TIL about console.dir

If you console.log a element, you will get it's HTML markup. If you want it as a JS object, use console.dir instead

TIL adding a debug flag for custom features

Creating your own ?debug flag in your url to do some sweet debug stuff

TIL about console.count and console.table

Some different ways to show data via your console