Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs 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 its URL and the proper URL extension.

+ 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

Auto Save

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

              
                console.clear();


/***** Var *****/
console.log( '***** Var *****');

// Global scope available to functions
var globalName = 'World';

function greet() {
  // Declared inside the greet() function
  var myName = globalName;
  console.log( 'Hello ' + myName );
  
  
  if ( myName === 'World' ) {
    var myOtherName = 'Sacramento';
  }
  
  // myOtherName is available outside of the if statement
  console.log( 'Hello ' + myOtherName );
  
}
greet();
// This will both error out because the variables are not defined outside of the function
// This will throw an error and terminate everything after it
// console.log( 'Hello ' + myName );
// console.log( 'Hello ' + myOtherName );



/***** const *****/
console.log( '***** Const *****');


function one() {
  const a = 1;
  // This would throw an error
  // Can't redefine constants inside a block
  // a = 2;
  
  console.log( a );
  
  if ( a === 1 ) {
    // You still can't reassign it, as its value is inherited.
    // This will throw an error
    // a = 2;
    
    // However, inside a block you can declare a new constant with the same name. 
    // This constant is scoped to just the if statement block
    const a = 2;
    // The value of a here is 2
    console.log( a );
  }

  // Outside the if block, the value remains 1
  console.log( a );
}
one();
// It doesn't exist here because it was declared inside the function one()
// This will throw an error and terminate everything after it
// console.log( a );



/**** let *****/
console.log( '***** Let *****');


function two() {
  let x = 1;
  // It's safe to reassign variables declared with let
  x = 2;
  
  // The value is 2
  console.log( x );
  
  if ( x === 2 ) {
    // Inside a block you can redeclare it
    // This is only scoped to the if statement
    let x = 3;
    // The value here is 3
    console.log( x );
  }

  // Outside the if block, the value remains 2
  console.log( x );
}
two();
// It doesn't exist here because it was declared inside the function one()
// console.log( x );
              
            
!
999px

Console