HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
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.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
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.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
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.
Using packages here is powered by esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<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>
<br>
<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>
body{
font-family:arial;
}
.highlight{
color:red;
background-color:yellow;
font-weight:bold;
font-size:large;
padding:3px;
}
//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> document.getElementById('result1').innerHTML=msg;<br>}<br>f1(message);</p><blockquote>";
function f1(msg) {
document.getElementById("result1").innerHTML=msg;
}
f1(message);
//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> document.getElementById('result2').innerHTML=msg; <br>}<br> <span class='highlight'>(</span>f2<span class='highlight'>)</span>(message);</blockquote>";
function f2(msg) {
document.getElementById("result2").innerHTML=msg;
}
(f2)(message);
//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> document.getElementById('result3').innerHTML=msg;<br> }<span class='highlight'>)</span>(message);</p></blockquote>";
(function foo(msg) {
document.getElementById("result3").innerHTML=msg;
})(message);
//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'> </span>(msg) { <br> document.getElementById('result4').innerHTML=msg;<br>})(message);</p></blockquote>";
(function (msg) {
document.getElementById("result4").innerHTML=msg;
})(message);
// 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'> </span>(msg)=>{<br> 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) => {
document.getElementById("result5").innerHTML=msg;
})(message);
Also see: Tab Triggers