snipt

Ctrl+h for KB shortcuts

JavaScript

single comment

// Single-line comment
https://snipt.net/embed/1085b8a42cf829af4b99c93aa983629f/
https://snipt.net/raw/1085b8a42cf829af4b99c93aa983629f/
1085b8a42cf829af4b99c93aa983629f
js
JavaScript
1
2016-09-21T18:19:01
True
False
False
Feb 19, 2013 at 10:51 AM
/api/public/snipt/56030/
single-comment
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">// Single-line comment</span> </span></pre></div> </td></tr></table>
"single comment", syntax

JavaScript

Array recomendable declaration

1
2
3
// Good
var colors = [ "red", "green", "blue" ];
var numbers = [ 1, 2, 3, 4 ];
https://snipt.net/embed/dcb305ced062018353edbc64edf3a9ac/
https://snipt.net/raw/dcb305ced062018353edbc64edf3a9ac/
dcb305ced062018353edbc64edf3a9ac
js
JavaScript
3
2016-09-21T20:24:56
True
False
False
Feb 18, 2013 at 10:54 AM
/api/public/snipt/55953/
array-recomendable-declaration
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">// Good</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">colors</span> <span class="o">=</span> <span class="p">[</span> <span class="s2">&quot;red&quot;</span><span class="p">,</span> <span class="s2">&quot;green&quot;</span><span class="p">,</span> <span class="s2">&quot;blue&quot;</span> <span class="p">];</span> </span><span id="L-3"><a name="L-3"></a><span class="kd">var</span> <span class="nx">numbers</span> <span class="o">=</span> <span class="p">[</span> <span class="mi">1</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mi">3</span><span class="p">,</span> <span class="mi">4</span> <span class="p">];</span> </span></pre></div> </td></tr></table>
array, recomendable, syntax

JavaScript

Object recomendable declaration

1
2
3
4
5
6
// Good
var web = {
    title: "MyWebsite",
    url: "http://localhost/",
    category: "blog"
};
https://snipt.net/embed/defc9439d4b648be0951d7b7de373540/
https://snipt.net/raw/defc9439d4b648be0951d7b7de373540/
defc9439d4b648be0951d7b7de373540
js
JavaScript
6
2016-09-26T15:04:33
True
False
False
Feb 18, 2013 at 10:50 AM
/api/public/snipt/55952/
object-recomendable-declaration
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</a> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="c1">// Good</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">web</span> <span class="o">=</span> <span class="p">{</span> </span><span id="L-3"><a name="L-3"></a> <span class="nx">title</span><span class="o">:</span> <span class="s2">&quot;MyWebsite&quot;</span><span class="p">,</span> </span><span id="L-4"><a name="L-4"></a> <span class="nx">url</span><span class="o">:</span> <span class="s2">&quot;http://localhost/&quot;</span><span class="p">,</span> </span><span id="L-5"><a name="L-5"></a> <span class="nx">category</span><span class="o">:</span> <span class="s2">&quot;blog&quot;</span> </span><span id="L-6"><a name="L-6"></a><span class="p">};</span> </span></pre></div> </td></tr></table>
javascript, object, syntax

JavaScript

String long declaration

var longString = "Here's the story, of a man " +
                 "named Brady.";
https://snipt.net/embed/ce93b10a92ec267e987462d7ef201197/
https://snipt.net/raw/ce93b10a92ec267e987462d7ef201197/
ce93b10a92ec267e987462d7ef201197
js
JavaScript
2
2016-09-27T08:10:10
True
False
False
Feb 18, 2013 at 09:50 AM
/api/public/snipt/55948/
string-long-declaration
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">longString</span> <span class="o">=</span> <span class="s2">&quot;Here&#39;s the story, of a man &quot;</span> <span class="o">+</span> </span><span id="L-2"><a name="L-2"></a> <span class="s2">&quot;named Brady.&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
long, string, syntax

JavaScript

Constants in JavaScript

var MAX_COUNT = 10;
var PATH_URL = "http://localhost/";
https://snipt.net/embed/c2787ddfe101a763f845162b9dc765df/
https://snipt.net/raw/c2787ddfe101a763f845162b9dc765df/
c2787ddfe101a763f845162b9dc765df
js
JavaScript
2
2016-09-22T00:06:37
True
False
False
Feb 17, 2013 at 10:57 PM
/api/public/snipt/55911/
constants-in-javascript
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span id="L-1"><a name="L-1"></a><span class="kd">var</span> <span class="nx">MAX_COUNT</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span> </span><span id="L-2"><a name="L-2"></a><span class="kd">var</span> <span class="nx">PATH_URL</span> <span class="o">=</span> <span class="s2">&quot;http://localhost/&quot;</span><span class="p">;</span> </span></pre></div> </td></tr></table>
constant, syntax
Copyrighted, illegal, or inappropriate content? Email support@snipt.net.