<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaScript syntax &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/javascript-syntax/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>You think you know javascript. Quiz results!</title>
		<link>/2012/03/07/you-think-you-know-javascript-quiz-results/</link>
		<comments>/2012/03/07/you-think-you-know-javascript-quiz-results/#comments</comments>
		<pubDate>Wed, 07 Mar 2012 10:27:37 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[quiz]]></category>
		<category><![CDATA[Client-side JavaScript]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=2854</guid>
		<description><![CDATA[After a week again, the &#8220;You think you know &#8230; JavaScript&#8221; quiz results are on! 1. Which loop is faster in JavaScript? for while correct answer 2. What will be alerted by the code bellow? var str = 'my-'; alert(str.split('-')[1]); Error An empty string correct answer &#8220;-&#8220; &#8220;my&#8221; 3. What is server-side JavaScript? JS scripts &#8230; <a href="/2012/03/07/you-think-you-know-javascript-quiz-results/" class="more-link">Continue reading <span class="screen-reader-text">You think you know javascript. Quiz results!</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-algorithms-quiz-results/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>After a week again, the &#8220;You think you know &#8230; JavaScript&#8221; quiz results are on!</p>
<p><strong>1. Which loop is faster in JavaScript?</strong></p>
<ul>
<li>for</li>
<li>while <span style="color: #339966;">correct answer</span></li>
</ul>
<p><figure id="attachment_2883" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer1.png"><img src="/wp-content/uploads/2012/03/answer1.png" alt="Answers of the first question chart" title="Answers of the first question chart" width="600" height="371" class="size-full wp-image-2883" srcset="/wp-content/uploads/2012/03/answer1.png 600w, /wp-content/uploads/2012/03/answer1-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text"> </figcaption></figure><br />
<span id="more-2854"></span><br />
<strong>2. What will be alerted by the code bellow? </strong></p>
<pre lang="javascript">var str = 'my-'; alert(str.split('-')[1]);</pre>
<ul>
<li>Error</li>
<li>An empty string <span style="color: #339966;">correct answer</span></li>
<li>&#8220;-&#8220;</li>
<li>&#8220;my&#8221;</li>
</ul>
<figure id="attachment_2885" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer2.png"><img src="/wp-content/uploads/2012/03/answer2.png" alt="Answers of the second question chart" title="Answers of the second question chart" width="600" height="371" class="size-full wp-image-2885" srcset="/wp-content/uploads/2012/03/answer2.png 600w, /wp-content/uploads/2012/03/answer2-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text"> </figcaption></figure>
<p><strong>3. What is server-side JavaScript?</strong></p>
<ul>
<li>JS scripts files placed on the server that can be publicly accessed by the client</li>
<li>JS engine running on the server accessible via http <span style="color: #339966;">correct answer</span></li>
</ul>
<figure id="attachment_2887" style="width: 600px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer3.png"><img src="/wp-content/uploads/2012/03/answer3.png" alt="Answers of the third question chart" title="Answers of the third question chart" width="600" height="371" class="size-full wp-image-2887" srcset="/wp-content/uploads/2012/03/answer3.png 600w, /wp-content/uploads/2012/03/answer3-300x185.png 300w" sizes="(max-width: 600px) 100vw, 600px" /></a><figcaption class="wp-caption-text">90.91% right answers</figcaption></figure>
<p><strong>4. Is it possible to have private and public methods in a JavaScript object</strong></p>
<ul>
<li>Yes <span style="color: #339966;">correct answer</span></li>
<li>No</li>
</ul>
<figure id="attachment_2889" style="width: 540px" class="wp-caption alignnone"><a href="/wp-content/uploads/2012/03/answer4.png"><img src="/wp-content/uploads/2012/03/answer4.png" alt="Answers of the fourth question chart" title="Answers of the fourth question chart" width="540" height="331" class="size-full wp-image-2889" srcset="/wp-content/uploads/2012/03/answer4.png 540w, /wp-content/uploads/2012/03/answer4-300x183.png 300w" sizes="(max-width: 540px) 100vw, 540px" /></a><figcaption class="wp-caption-text">54.55% answered with the right answer!</figcaption></figure>
<p><em>Note that the quiz will remain open, but no results will be published!</em></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2012/02/29/you-think-you-know-algorithms-quiz-results/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/03/16/you-think-you-know-php-quiz-results/" rel="bookmark" title="You think you know PHP. Quiz Results!">You think you know PHP. Quiz Results! </a></li>
<li><a href="/2012/05/09/you-think-you-know-algorithms-quiz-results-2/" rel="bookmark" title="You think you know algorithms. Quiz results!">You think you know algorithms. Quiz results! </a></li>
<li><a href="/2012/01/24/javascript-performance-for-vs-while/" rel="bookmark" title="JavaScript Performance: for vs. while">JavaScript Performance: for vs. while </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2012/03/07/you-think-you-know-javascript-quiz-results/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>A JavaScript Trick You Should Know</title>
		<link>/2011/07/12/a-javascript-trick-you-should-know/</link>
		<comments>/2011/07/12/a-javascript-trick-you-should-know/#comments</comments>
		<pubDate>Tue, 12 Jul 2011 14:49:46 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Brace notation]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Concatenation]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Formal languages]]></category>
		<category><![CDATA[heredoc]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[js solution]]></category>
		<category><![CDATA[possible solution]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[String]]></category>

		<guid isPermaLink="false">/?p=2333</guid>
		<description><![CDATA[JavaScript Strings You should know that in JavaScript you cannot simply write a multilined code chunk, i.e. something like this: var str = 'hello world'; This will result in an error, which can be a problem when you deal with large strings. Imagine a string containing some HTML that should be injected via innerHTML. Now &#8230; <a href="/2011/07/12/a-javascript-trick-you-should-know/" class="more-link">Continue reading <span class="screen-reader-text">A JavaScript Trick You Should Know</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/08/26/javascript-flexibility-regex-match/" rel="bookmark" title="JavaScript Flexibility &#8211; Regex match()">JavaScript Flexibility &#8211; Regex match() </a></li>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
<li><a href="/2010/08/25/flexible-javascript-replace-in-a-string/" rel="bookmark" title="Flexible JavaScript &#8211; Replace in a String">Flexible JavaScript &#8211; Replace in a String </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Strings</h2>
<p>You should know that in JavaScript you cannot simply write a multilined code chunk, i.e. something like this:</p>
<pre lang="javascript">
var str = 'hello
world';
</pre>
<p>This will result in an error, which can be a problem when you deal with large strings. Imagine a string containing some HTML that should be injected via innerHTML. Now one possible solution is to concatenate two or more strings, by splitting the initial string.</p>
<pre lang="javascript">
var str = 'hello'
        + 'world';
</pre>
<p>Howerver this solution result in some additional operations like concatenation. It can be very nice if there was something like the PHP multiline string format.</p>
<h2>The PHP Example</h2>
<p>In PHP you have the same use case with strings. You can have a string concatenated over multiple lines, but you cannot split lines like so:</p>
<pre lang="php">
// the following line is wrong
$str = 'hello
world'; 

// a possible solution to the line above is
$str = 'hello'
     . 'world';
// which is very similar to the js solution in the second example

// ... but in PHP there is the so called HEREDOC
$str = <<<EOD
hello
world
EOD;
</pre>
<p>The heredoc gives us the power to write multiline strings. </p>
<h2>The JavaScript Trick</h2>
<p>Actually in JavaScript there is something that's exactly what Heredoc is meant to be for PHP. Take a look at the last example:</p>
<pre lang="javascript">
var text = <>
this <br />
is
my
multi-line
text
</>.toString();

document.body.innerHTML = text;
</pre>
<p>Thus you can write multiline strings in the JavaScript code.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
<li><a href="/2010/08/26/javascript-flexibility-regex-match/" rel="bookmark" title="JavaScript Flexibility &#8211; Regex match()">JavaScript Flexibility &#8211; Regex match() </a></li>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
<li><a href="/2010/08/25/flexible-javascript-replace-in-a-string/" rel="bookmark" title="Flexible JavaScript &#8211; Replace in a String">Flexible JavaScript &#8211; Replace in a String </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2011/07/12/a-javascript-trick-you-should-know/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript Flexibility &#8211; Regex match()</title>
		<link>/2010/08/26/javascript-flexibility-regex-match/</link>
		<comments>/2010/08/26/javascript-flexibility-regex-match/#respond</comments>
		<pubDate>Thu, 26 Aug 2010 13:28:04 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=1927</guid>
		<description><![CDATA[Today after two posts [#1, #2] in the past days here&#8217;s something that shows again the JavaScript power. This is not a complete example, but it&#8217;s good to start. var str = '/text/1/text/2/'; var a = str.match(/(\d+)/gi); console.log(a); in that example you&#8217;ll get an array with all the numbers in the string [&#8220;1&#8221;, &#8220;2&#8221;] &#8211; &#8230; <a href="/2010/08/26/javascript-flexibility-regex-match/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Flexibility &#8211; Regex match()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Today after two posts [<a href="/2010/08/24/flexible-javascript-splitting-strings/" target="_blank">#1</a>, <a href="/2010/08/25/flexible-javascript-replace-in-a-string/" target="_blank">#2</a>] in the past days here&#8217;s something that shows again the JavaScript power. This is not a complete example, but it&#8217;s good to start.</p>
<pre lang="javascript">var str = '/text/1/text/2/';
var a = str.match(/(\d+)/gi);
console.log(a);
</pre>
<p>in that example you&#8217;ll get an array with all the numbers in the string [&#8220;1&#8221;, &#8220;2&#8221;] &#8211; yet another flexible js snippet!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/02/02/profiling-javascript-with-firebug-console-profile-console-time/" rel="bookmark" title="Profiling JavaScript with Firebug. console.profile() &#038; console.time()!">Profiling JavaScript with Firebug. console.profile() &#038; console.time()! </a></li>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/26/javascript-flexibility-regex-match/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Flexible JavaScript &#8211; Replace in a String</title>
		<link>/2010/08/25/flexible-javascript-replace-in-a-string/</link>
		<comments>/2010/08/25/flexible-javascript-replace-in-a-string/#respond</comments>
		<pubDate>Wed, 25 Aug 2010 12:36:02 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[web development]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[Parameter]]></category>
		<category><![CDATA[Pattern matching]]></category>
		<category><![CDATA[Perl 6 rules]]></category>
		<category><![CDATA[Regular expression]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=1923</guid>
		<description><![CDATA[Here&#8217;s yet another example of the JavaScript flexibility. You can simply call .replace() on every string and pass a regex as a parameter! var str = 'my simple string'; str.replace(/ /g, '-'); // now 'str' will contain 'my-simple-string'<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
<li><a href="/2010/08/26/javascript-flexibility-regex-match/" rel="bookmark" title="JavaScript Flexibility &#8211; Regex match()">JavaScript Flexibility &#8211; Regex match() </a></li>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Here&#8217;s yet another example of the JavaScript flexibility. You can simply call .replace() on every string and pass a regex as a parameter!</p>
<pre lang="javascript">
var str = 'my simple string';
str.replace(/ /g, '-'); // now 'str' will contain 'my-simple-string'
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/24/flexible-javascript-splitting-strings/" rel="bookmark" title="Flexible JavaScript &#8211; Splitting Strings">Flexible JavaScript &#8211; Splitting Strings </a></li>
<li><a href="/2010/08/26/javascript-flexibility-regex-match/" rel="bookmark" title="JavaScript Flexibility &#8211; Regex match()">JavaScript Flexibility &#8211; Regex match() </a></li>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/25/flexible-javascript-replace-in-a-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Quick Look at JavaScript Objects</title>
		<link>/2010/08/11/quick-look-at-javascript-objects/</link>
		<comments>/2010/08/11/quick-look-at-javascript-objects/#respond</comments>
		<pubDate>Wed, 11 Aug 2010 17:38:55 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[C++ classes]]></category>
		<category><![CDATA[Class]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[JSON]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Set-builder notation]]></category>
		<category><![CDATA[Software engineering]]></category>

		<guid isPermaLink="false">/?p=1900</guid>
		<description><![CDATA[JavaScript Objects As you may know there are different notations of objects in JavaScript, and there are slight differences. However here I&#8217;m gonna achieve the same thing with different notations. The first one is the object notation in JavaScript known mostly from JSON. There you&#8217;ve to construct a key/value pairs, divided by a colon: var &#8230; <a href="/2010/08/11/quick-look-at-javascript-objects/" class="more-link">Continue reading <span class="screen-reader-text">Quick Look at JavaScript Objects</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript Objects</h2>
<p>As you may know there are different notations of objects in JavaScript, and there are slight differences. However here I&#8217;m gonna achieve the same thing with different notations. The first one is the object notation in JavaScript known mostly from JSON. There you&#8217;ve to construct a key/value pairs, divided by a colon:</p>
<pre lang="javascript">
var class1 = {
    a : 0,
    func1 : function() {
        console.log(class1.a);
    },
    func2 : function(a) {
        this.a = a;
    }
}
class1.func2(3);
</pre>
<p>Here we have two functions &#8211; func1 and func2 and one member variable. Func2 is setting up the member variable, it&#8217;s something like a setter in some languages like Java and PHP, and the func1 is printing the value of that variable via console.log(). Note that in the body of func1() the variable &#8220;a&#8221; is accessed with the class name: class1.a. Here the notation can be changed to this.a, which will result in the same thing.</p>
<pre lang="javascript">
...
console.log(this.a);
...
</pre>
<h2>Notation #2</h2>
<p>While in the notation I&#8217;ve just used is not possible to have two different instances from the same class, in the next example this is possible. In JavaScript the objects are even the functions, and you can access the function&#8217;s private variables with the dot notation.</p>
<pre lang="javascript">
var class2 = function() {
    this.a = 0;
    this.func1 = function() {
        console.log(this.a);
    }

    this.func2 = function(a) {
        this.a = a;
    }
}
</pre>
<p>To use this object you&#8217;ve to use the &#8220;new&#8221; operator.</p>
<pre lang="javascript">
var c = new class2();
c.func2(4);
</pre>
<p>This helps you create more than one instance of the same class.</p>
<pre lang="javascript">
var c = new class2();
var d = new class2();
c.func2(3);
d.func2(4);
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2009/07/08/javascript-closures-in-brief/" rel="bookmark" title="JavaScript closures in brief">JavaScript closures in brief </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/11/quick-look-at-javascript-objects/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript array.pop() &#8211; Get The Last Item</title>
		<link>/2010/06/14/javascript-array-pop-get-the-last-item/</link>
		<comments>/2010/06/14/javascript-array-pop-get-the-last-item/#respond</comments>
		<pubDate>Mon, 14 Jun 2010 13:30:18 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>

		<guid isPermaLink="false">/?p=1611</guid>
		<description><![CDATA[Let&#8217;s assume there&#8217;s a little, simple JavaScript array: var a = [3,2,4,5,2,4,5,8]; If you pop() an element from it &#8211; what element will be taken? The answer is a bit frustrating, but logical &#8211; the last one: var b = a.pop(); alert(b); // this will result in 8<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2010/01/09/array-hint-in-javascript/" rel="bookmark" title="Array hint in JavaScript">Array hint in JavaScript </a></li>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2010/07/16/friday-algorithms-a-data-structure-javascript-stack/" rel="bookmark" title="Friday Algorithms: A Data Structure: JavaScript Stack">Friday Algorithms: A Data Structure: JavaScript Stack </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>Let&#8217;s assume there&#8217;s a little, simple JavaScript array:</p>
<pre lang="javascript">
var a = [3,2,4,5,2,4,5,8];
</pre>
<p>If you pop() an element from it &#8211; what element will be taken? The answer is a bit frustrating, but logical &#8211; the last one:</p>
<pre lang="javascript">
var b = a.pop();
alert(b); // this will result in 8
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2010/01/09/array-hint-in-javascript/" rel="bookmark" title="Array hint in JavaScript">Array hint in JavaScript </a></li>
<li><a href="/2010/02/12/how-to-detect-a-variable-existence-in-javascript/" rel="bookmark" title="How to detect a variable existence in JavaScript?">How to detect a variable existence in JavaScript? </a></li>
<li><a href="/2010/07/16/friday-algorithms-a-data-structure-javascript-stack/" rel="bookmark" title="Friday Algorithms: A Data Structure: JavaScript Stack">Friday Algorithms: A Data Structure: JavaScript Stack </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/06/14/javascript-array-pop-get-the-last-item/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript Objects Coding Style</title>
		<link>/2010/05/24/javascript-objects-coding-style/</link>
		<comments>/2010/05/24/javascript-objects-coding-style/#comments</comments>
		<pubDate>Mon, 24 May 2010 07:48:50 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[Associative array]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[Negation]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Scripting languages]]></category>

		<guid isPermaLink="false">/?p=1557</guid>
		<description><![CDATA[JavaScript vs. PHP Continuing from my post about PHP arrays coding style and following the comments of that post, I&#8217;d like to write a bit about JavaScript objects&#8217; coding style. You perhaps know that the term object is quite undefined or under estimated in the JavaScript world, but I&#8217;d speak about the key/value pairs in &#8230; <a href="/2010/05/24/javascript-objects-coding-style/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Objects Coding Style</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/12/03/javascript-objects-coding-style-reviewed/" rel="bookmark" title="JavaScript Objects Coding Style Reviewed">JavaScript Objects Coding Style Reviewed </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/02/24/storing-javascript-objects-in-html5-localstorage/" rel="bookmark" title="Storing JavaScript objects in html5 localStorage">Storing JavaScript objects in html5 localStorage </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript vs. PHP</h2>
<p>Continuing from my <a title="PHP Arrays Coding Style" href="/2010/05/19/php-associative-arrays-coding-style/" target="_self">post</a> about PHP arrays coding style and following the comments of that post, I&#8217;d like to write a bit about JavaScript objects&#8217; coding style.</p>
<p>You perhaps know that the term object is quite undefined or under estimated in the JavaScript world, but I&#8217;d speak about the key/value pairs in JS commonly formatted like that:</p>
<pre lang="javascript">
var obj = { key : 'value' }
</pre>
<p>Here you can add more and more key/value pairs, but what&#8217;s different from the PHP associative arrays and what&#8217;s the same and should be cosidered.</p>
<h2>The Same as PHP?</h2>
<p>I wrote about the alignment in PHP and hashes. Than I showed how I align them:</p>
<pre lang="php">
$arr = array(
   'short'   => 'val',
   'longkey' => 'val'
);
</pre>
<p>In JavaScript you should use the same technique of alignment:</p>
<pre lang="php">
var obj = {
   'short'   : 'val',
   'longkey' : 'val'
};
</pre>
<h2>Some Differences</h2>
<p>Yes, there are more differences, which is normal. First of all you don&#8217;t have the =&gt; notation in JavaScript and a : is used. Second and most important you cannot add a trailing comma after the last key/value pair. Note that in PHP that&#8217;s fine!</p>
<pre lang="javascript">
// that will throw an error in MSIE
var obj = {
   'short'   : 'val',
   'longkey' : 'val',
};
</pre>
<p>while this is OK in PHP and it&#8217;s encouraged:</p>
<pre lang="php">
$arr = array(
   'short'   => 'val',
   'longkey' => 'val',
);
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/12/03/javascript-objects-coding-style-reviewed/" rel="bookmark" title="JavaScript Objects Coding Style Reviewed">JavaScript Objects Coding Style Reviewed </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2010/02/24/storing-javascript-objects-in-html5-localstorage/" rel="bookmark" title="Storing JavaScript objects in html5 localStorage">Storing JavaScript objects in html5 localStorage </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/05/24/javascript-objects-coding-style/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript Snippets: IF Statements Optimization</title>
		<link>/2010/03/14/javascript-snippets-if-statements-optimization/</link>
		<comments>/2010/03/14/javascript-snippets-if-statements-optimization/#comments</comments>
		<pubDate>Sun, 14 Mar 2010 18:28:46 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[Scripting languages]]></category>
		<category><![CDATA[Technology/Internet]]></category>

		<guid isPermaLink="false">/?p=1307</guid>
		<description><![CDATA[A &#8220;Typical Installation&#8221; &#8230; As most of the desktop software gives us opportunity to choose from typical or custom installations, let me write what&#8217;s a typical IF conditional statement in JavaScript and &#8230; every other programing language. if ( thisIsTrue ) { printMe("some message"); } A &#8220;Custom Installation&#8221; &#8230; The first thing you can improve &#8230; <a href="/2010/03/14/javascript-snippets-if-statements-optimization/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript Snippets: IF Statements Optimization</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/14/javascript-snippets-if-statements-optimization-part-2/" rel="bookmark" title="JavaScript Snippets: IF Statements Optimization Part 2">JavaScript Snippets: IF Statements Optimization Part 2 </a></li>
<li><a href="/2010/02/07/javascript-optimization-optimizing-if-statements/" rel="bookmark" title="JavaScript optimization. Optimizing IF statements.">JavaScript optimization. Optimizing IF statements. </a></li>
<li><a href="/2010/02/11/javascript-optimization-lazy-loading/" rel="bookmark" title="JavaScript optimization. Lazy loading.">JavaScript optimization. Lazy loading. </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>A &#8220;Typical Installation&#8221; &#8230;</h2>
<p>As most of the desktop software gives us opportunity to choose from typical or custom installations, let me write what&#8217;s a typical IF conditional statement in JavaScript and &#8230; every other programing language.</p>
<pre lang="javascript">if ( thisIsTrue ) {
    printMe("some message");
}
</pre>
<h2>A &#8220;Custom Installation&#8221; &#8230;</h2>
<p>The first thing you can improve from the code above is removing the brackets.</p>
<pre lang="javascript">if ( thisIsTrue )
    printMe("someMessage");
</pre>
<p>Because in JavaScript everything&#8217;s on the client &#8211; every symbol matters. What if we remove as much as we can!</p>
<pre lang="javascript" escaped="true">thisIsTrue &amp;&amp; printMe("someMessage");
</pre>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/14/javascript-snippets-if-statements-optimization-part-2/" rel="bookmark" title="JavaScript Snippets: IF Statements Optimization Part 2">JavaScript Snippets: IF Statements Optimization Part 2 </a></li>
<li><a href="/2010/02/07/javascript-optimization-optimizing-if-statements/" rel="bookmark" title="JavaScript optimization. Optimizing IF statements.">JavaScript optimization. Optimizing IF statements. </a></li>
<li><a href="/2010/02/11/javascript-optimization-lazy-loading/" rel="bookmark" title="JavaScript optimization. Lazy loading.">JavaScript optimization. Lazy loading. </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/14/javascript-snippets-if-statements-optimization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>JavaScript inheritance example</title>
		<link>/2010/03/02/javascript-inheritance-example/</link>
		<comments>/2010/03/02/javascript-inheritance-example/#respond</comments>
		<pubDate>Tue, 02 Mar 2010 15:24:46 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Inheritance]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[Object-oriented programming]]></category>

		<guid isPermaLink="false">/?p=1177</guid>
		<description><![CDATA[JavaScript and inheritance Almost for everybody the JavaScript way of implementing inheritance is odd. For a typical programmer it should look more C or Java like, but is not. However to give you a breve example, I&#8217;d like to make two objects, and to make the second one to inherit from the first. Thus I&#8217;d &#8230; <a href="/2010/03/02/javascript-inheritance-example/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript inheritance example</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>JavaScript and inheritance</h2>
<p>Almost for everybody the JavaScript way of implementing inheritance is odd. For a typical programmer it should look more C or Java like, but is not. However to give you a breve example, I&#8217;d like to make two objects, and to make the second one to inherit from the first. Thus I&#8217;d like to show how neither parent or child objects interact once they have been instanciated.</p>
<pre lang="javascript" line="1">
	var parent = function() {};
	parent.prototype = {
		name : 'parent',
		m : 1,
		a : function() {
			console.log(this.name + ': ' + this.m);
		},
		setM : function( value ) {
			this.m = value;
		}
	};
	
	var child = function() {};
	child.prototype = new parent;
	child.prototype.name = 'child';
	
	var parentObj = new parent();
	var childObj = new child();
	
	parentObj.a();
	parentObj.setM(12);
	
	childObj.a();
	childObj.setM(3);
	
	parentObj.a();
	childObj.a();
</pre>
<p>However this describes the ability to make complex JavaScript inheritance patterns. The complete source&#8217;s <a href="http://http://www.stoimen.com/projects/javascript.inheritance/" target="_blank">here</a>.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2011/05/30/object-oriented-javascript-inheritance/" rel="bookmark" title="Object Oriented JavaScript: Inheritance">Object Oriented JavaScript: Inheritance </a></li>
<li><a href="/2010/08/11/quick-look-at-javascript-objects/" rel="bookmark" title="Quick Look at JavaScript Objects">Quick Look at JavaScript Objects </a></li>
<li><a href="/2011/07/28/oop-javascript-accessing-public-methods-in-private-methods/" rel="bookmark" title="OOP JavaScript: Accessing Public Methods in Private Methods">OOP JavaScript: Accessing Public Methods in Private Methods </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/03/02/javascript-inheritance-example/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JavaScript optimization. Optimizing IF statements.</title>
		<link>/2010/02/07/javascript-optimization-optimizing-if-statements/</link>
		<comments>/2010/02/07/javascript-optimization-optimizing-if-statements/#respond</comments>
		<pubDate>Sun, 07 Feb 2010 07:51:41 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Conditional]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>
		<category><![CDATA[myFunc]]></category>

		<guid isPermaLink="false">/?p=1053</guid>
		<description><![CDATA[IF statements in JavaScript and the normal world! In fact every normal developer will try to make his code as readable as possible. In a normal world a JavaScript IF statement will look like so: if ( expression ) myFunc(); where expression is something that can be either true or false and myFunc is just &#8230; <a href="/2010/02/07/javascript-optimization-optimizing-if-statements/" class="more-link">Continue reading <span class="screen-reader-text">JavaScript optimization. Optimizing IF statements.</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/03/14/javascript-snippets-if-statements-optimization/" rel="bookmark" title="JavaScript Snippets: IF Statements Optimization">JavaScript Snippets: IF Statements Optimization </a></li>
<li><a href="/2010/03/14/javascript-snippets-if-statements-optimization-part-2/" rel="bookmark" title="JavaScript Snippets: IF Statements Optimization Part 2">JavaScript Snippets: IF Statements Optimization Part 2 </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>IF statements in JavaScript and the normal world!</h2>
<p>In fact every normal developer will try to make his code as readable as possible. In a normal world a JavaScript IF statement will look like so:</p>
<blockquote>
<pre>if ( expression ) myFunc();</pre>
</blockquote>
<p>where expression is something that can be either true or false and myFunc is just an example what can be called if the expression is true.</p>
<h2>But that&#8217;s JavaScript?!</h2>
<p>Yes, and just because is JavaScript every single character is important. Actually you can convert the row above with that one bellow:</p>
<blockquote>
<pre>expression &amp;&amp; myFunc()</pre>
</blockquote>
<p>Than if expression is faulty myFunc() will not be called. That is really extreme and in the same time is quite clear to read.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/03/14/javascript-snippets-if-statements-optimization/" rel="bookmark" title="JavaScript Snippets: IF Statements Optimization">JavaScript Snippets: IF Statements Optimization </a></li>
<li><a href="/2010/03/14/javascript-snippets-if-statements-optimization-part-2/" rel="bookmark" title="JavaScript Snippets: IF Statements Optimization Part 2">JavaScript Snippets: IF Statements Optimization Part 2 </a></li>
<li><a href="/2010/03/09/what-make-javascript-closures-work/" rel="bookmark" title="What make JavaScript closures work?">What make JavaScript closures work? </a></li>
<li><a href="/2011/07/12/a-javascript-trick-you-should-know/" rel="bookmark" title="A JavaScript Trick You Should Know">A JavaScript Trick You Should Know </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/02/07/javascript-optimization-optimizing-if-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
