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.

              <h1>The FUN thing about Functions in JavaScript</h1>
<blockquote>What the Heck is a JavaScript Function Anyway? Even old programmers are mystified at times by the liberty JavaScript takes with functions. However, this approach is often what makes JavaScript so appealing to some. Here is a step-by-step explanation of what I mean.</blockquote>
<blockquote>You may know that JavaScript functions can be written in variable structure "var test = function(x){...}" or a standard named "declaration notation" function call. We'll be utilizing the declaration notarion for this example to illustrate how function logic and usage has developed.</blockquote>
<div id="result1"></div>
<div id="result2"></div>
<div id="result3"></div>
<div id="result4"></div>
<div id="result5"></div>
<blockquote>Thank you for viewing this code demo! ~ Dan  :-]></blockquote>
//Ex. 1: A standard function:
var message = "<strong>EXAMPLE 1.) A Standard Function:</strong> This is a standard function call.<blockquote><p> function f1(msg) {<br>&nbsp;&nbsp;&nbsp;&nbsp;   document.getElementById('result1').innerHTML=msg;<br>}<br>f1(message);</p><blockquote>";

function f1(msg) {

//Ex. 2: Standard function, grouped
var message = "<strong>EXAMPLE 2.) \"Call Wrapping\" the Function Call: </strong> Here is the same type of function. However, since function calls are objects, they can be grouped. Putting a parenthesis around the call still works! See the next example for why that is important.<blockquote><p> function f2(msg) {<br>&nbsp;&nbsp;&nbsp;&nbsp;   document.getElementById('result2').innerHTML=msg; <br>}<br> <span class='highlight'>(</span>f2<span class='highlight'>)</span>(message);</blockquote>";

function f2(msg) {

//Ex. 3. Calling a Function without a named call
var message = "<strong>EXAMPLE 3.) Wrapping the entire function as a call.</strong> Since a call is the function object, the function call can be used without the named call at all. This is all fascilitated by the parenthesis now wrapping the entire function. <blockquote><p> <span class='highlight'>(</span>function foo(msg) {<br>&nbsp;&nbsp;&nbsp;&nbsp;     document.getElementById('result3').innerHTML=msg;<br> }<span class='highlight'>)</span>(message);</p></blockquote>";
(function foo(msg) {

//Ex. 4. An Anonymouse Function Call
var message = "<strong>EXAMPLE 4.) An Anonymouse Function Call:</strong> Because of this, you don't need the function name either!<blockquote><p>(function<span class='highlight'>&nbsp;&nbsp;</span>(msg) { <br>&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById('result4').innerHTML=msg;<br>})(message);</p></blockquote>";
(function (msg) { 

// Ex. 5. EC6 Shorthand - We don't need the keyword function either with EC6, use => instead.
var message = "<strong>EXAMPLE 5.) An Anonymouse Call Without the 'Function' Keyword:</strong> Nore do you need the function keyword itself!<blockquote><p>(<span class='highlight'>&nbsp;</span>(msg)=>{<br>&nbsp;&nbsp;&nbsp;&nbsp;document.getElementById('result5').innerHTML=msg;<br>})(message);</p></blockquote><blockquote>With ES6 that can use only a parameter and a structure, we are practically left with just an equation!:<p> ((param)=>{ //Do something })(param));</p></blockquote>";
((msg) => { 

🕑 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 ..................