css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

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. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation


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.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

              JavaScript \`is\` Helper Function

\`is\` can be used with every object and allows you to get its class as String. This is more consistend as the use of the JavaScript \`typeof\` function and allows better detection of native classes.

@license MIT

See [Using toString() to detect object class](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString#Using_toString_to_detect_object_type) for more details, or take a look to the code.

Here are some comparisation asserts between [typeof](#typeof) and [is](#is):
  padding: 10px;
  background: linear-gradient(
      #333 25%,
      #222 25%,
      #222 50%,
      #222 50%,
      #333 50%,
      #333 75%,
      #222 75%
  background-size: 64px 64px;
  font-family: monospace;
  font-weight: bold;
  color: #fff;

  color: #fff;

  padding: 20px;
  margin-bottom: 5px;
  border-radius: 8px;

  background-color: #393;
  border-left: 20px solid #363;

  background-color: #933;
  border-left: 20px solid #633;
// @section Definition of `is` helper function

 * Returns the internal class name of the given object.
 * @see {Using toString() to detect object class|https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString#Using_toString_to_detect_object_type}
 * @param {*} value
 * @return {String} 'Array', 'Boolean', 'Date', 'Number', 'Object' etc.
function is(value)
  var string = Object.prototype.toString.call(value);

  // `string` contains something like "[object Object]"
  // so extract the interessting part:         ^^^^^^.
  // Quite simple :-)
  return string.substring(8, string.length - 1);

// @section Demo

var asserts = document.createElement('div');

function createAssertElement(text, result)
  var assert = document.createElement('div');
  assert.classList.add('assert', result ? 'assert-success' : 'assert-fail');
  assert.innerHTML = text;
  return assert;

function assert(text, result)
  asserts.appendChild(createAssertElement(text, result));

header = document.createElement('h3');
header.textContent = 'typeof ...';
header.id = 'typeof';

assert('typeof true == "boolean"', typeof true == "boolean");
assert('typeof [ 1, 2, 3 ] == "array"', typeof [ 1, 2, 3 ] == "array");
assert('typeof tfunction(){}rue == "boolean"', typeof function(){} == "function");
assert('typeof new Date() == "date"', typeof new Date() == "date");
assert('typeof 0x133700 == "number"', typeof 0x133700 == "number");
assert('typeof { a: 1 } == "object"', typeof { a: 1 } == "object");
assert('typeof /test/ == "regexp"', typeof /test/ == "regexp");
assert('typeof "foobar" == "string"', typeof "foobar" == "string");
assert('typeof new function(){} == "object"', typeof new function(){} == "object");
assert('typeof document == "htmldocument"', typeof document == "htmldocument");

header = document.createElement('h3');
header.textContent = 'is(...)';
header.id = 'is';

assert('is(true) == "Boolean"', is(true) == "Boolean");
assert('is([ 1, 2, 3 ]) == "Array"', is([ 1, 2, 3 ]) == "Array");
assert('is(function(){}) == "Function"', is(function(){}) == "Function");
assert('is(new Date()) == "Date"', is(new Date()) == "Date");
assert('is(0x133700) == "Number"', is(0x133700) == "Number");
assert('is({ a: 1 }) == "Object"', is({ a: 1 }) == "Object");
assert('is(/test/) == "RegExp"', is(/test/) == "RegExp");
assert('is("foobar") == "String"', is("foobar") == "String");
assert('is(new function(){}) == "Object"', is(new function(){}) == "Object");
assert('is(document) == "HTMLDocument"', is(document) == "HTMLDocument");
// and so on.

🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................