<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Can Avcı on Medium]]></title>
        <description><![CDATA[Stories by Can Avcı on Medium]]></description>
        <link>https://medium.com/@canavci?source=rss-417b53a4256c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*OCxh5paBFMN-SmsBk1AGjg.jpeg</url>
            <title>Stories by Can Avcı on Medium</title>
            <link>https://medium.com/@canavci?source=rss-417b53a4256c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 11:24:12 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@canavci/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Javascript primitive and non primitives]]></title>
            <link>https://canavci.medium.com/javascript-primitive-and-non-primitives-942e5fa41bac?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/942e5fa41bac</guid>
            <category><![CDATA[mutable-objects]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Mon, 21 Apr 2025 10:37:49 GMT</pubDate>
            <atom:updated>2025-04-21T10:37:49.009Z</atom:updated>
            <content:encoded><![CDATA[<p>in javascript data types are categorized in primitives and non primitives which covering various types.</p><p>before explaining it lets go deep into the <strong>stack</strong> and <strong>heap. </strong>in the end you will gain broad idea about the concept of primitives.</p><h3>Stack?</h3><p>Stack is a data structure that obeys the Last In First Out (LIFO) principle</p><h3>Heap?</h3><p>Reference data are stored inside the heap. When reference data is created, the variable of the data is placed on the stack but the actual value is placed on the heap.</p><h3>Primitives</h3><p>primitive types are string, number, null, symbol, dundefined, and boolean this types are passed by value. whereas non-primitive types are passed by their reference objects, arrays, and functions</p><pre>let str=&quot;hello&quot;;<br>str[0]=&#39;c&#39;;<br>console.log(str);<br><br>// output<br>&gt; hello</pre><h3>Non-Primitives</h3><p>By default, non-primitives data types are mutable. Reference data types consist of Functions, Arrays, and Objects.</p><h3>What is Mutability in JavaScript?</h3><p>If a data type is mutable, that means that you can change it. Mutability allows you to modify existing values without creating new ones.</p><p>For every object, a pointer is added to the stack, and this pointer points to the object on the heap.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=942e5fa41bac" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Checking class through “instanceof”]]></title>
            <link>https://canavci.medium.com/checking-class-through-instanceof-dc8402ee0e58?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/dc8402ee0e58</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 10:18:47 GMT</pubDate>
            <atom:updated>2023-01-03T10:18:47.936Z</atom:updated>
            <content:encoded><![CDATA[<p>“<strong>instanceof</strong>” operator allows to check if an object belongs to a certain class.<br>Such check may be necessary in many cases.</p><pre>obj instanceof Class. // it returns true if it is instance of the given class</pre><pre>class Rabbit {}<br>let rabbit = new Rabbit();<br><br>// is it an object of Rabbit class?<br>alert( rabbit instanceof Rabbit ); // true</pre><pre>// instead of class<br>function Rabbit() {}<br><br>alert( new Rabbit() instanceof Rabbit ); // true</pre><p>moreover . it is also used for builtin classess</p><pre>let arr = [1, 2, 3];<br>alert( arr instanceof Array ); // true<br>alert( arr instanceof Object ); // true</pre><p><strong>arr</strong> also belongs to Object class. As <strong>Array</strong> class prototypically inherits from <strong>Object</strong> class. Normally <strong>instanceof</strong> operator examines the prototype chains</p><p>furthermore, we can set a custom logic in the [Symbol.hasInstance]</p><p>the algorithm of “<strong>instanceof</strong>” rougly as follows.</p><p>1-) check if there is a static Symbol.hasInstance . if it is so. then just call it . that is how we can customize it</p><pre>// setup instanceOf check that assumes that<br>// anything with canEat property is an animal<br>class Animal {<br>  static [Symbol.hasInstance](obj) {<br>    if (obj.canEat) return true;<br>  }<br>}<br><br>let obj = { canEat: true };<br><br>alert(obj instanceof Animal); // true: Animal[Symbol.hasInstance](obj) is called</pre><p>2-) Most classes dont have this method. in this case standart logic is applied. “instanceOf” operator checks whether Class.prototype is equal to one of the prototypes in the obj prototype chain.</p><p>In other words, compare one after another:</p><pre>// obj instanceOf Class<br><br>obj.__proto__ === Class.prototype?<br>obj.__proto__.__proto__ === Class.prototype?<br>obj.__proto__.__proto__.__proto__ === Class.prototype?</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dc8402ee0e58" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Overriding class fields]]></title>
            <link>https://canavci.medium.com/overriding-class-fields-19d656317edd?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/19d656317edd</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 13:35:17 GMT</pubDate>
            <atom:updated>2023-01-02T13:35:17.353Z</atom:updated>
            <content:encoded><![CDATA[<p>we can not only override methods but also fields . However there is tricky <strong>behavior</strong> when we access to the overridden field in the parent constructor and it is quite different from the most of the programming languages.</p><pre>class Animal {<br>  name = &#39;animal&#39;;<br><br>  constructor() {<br>    alert(this.name); // (*)<br>  }<br>}<br><br>class Rabbit extends Animal {<br>  name = &#39;rabbit&#39;;<br>}<br><br>new Animal(); // animal<br>new Rabbit(); // animal</pre><p>what is interesting , in both cases new Animal() and new Rabbit(), the alert in the line (*) shows animal.<br><strong>in other words a parent constructor always uses its own value<br></strong>If it’s not clear yet, please compare with methods.</p><pre>class Animal {<br>  showName() {  // instead of this.name = &#39;animal&#39;<br>    alert(&#39;animal&#39;);<br>  }<br><br>  constructor() {<br>    this.showName(); // instead of alert(this.name);<br>  }<br>}<br><br>class Rabbit extends Animal {<br>  showName() {<br>    alert(&#39;rabbit&#39;);<br>  }<br>}<br><br>new Animal(); // animal<br>new Rabbit(); // rabbit</pre><p>now the output is different . that is what we naturally expect when the parent constructor is called in the derived class.<br>But for fields it is not so.</p><p><strong>the reason is the initialization order since super class constructor is called before the derived ones.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19d656317edd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Object properties]]></title>
            <link>https://canavci.medium.com/object-properties-9c991978f792?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c991978f792</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Mon, 02 Jan 2023 13:18:48 GMT</pubDate>
            <atom:updated>2023-01-02T13:18:48.007Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/preventExtensions"><strong>Object.preventExtensions(obj)</strong></a><strong> : </strong>Forbids the addition of new properties to the object.</p><pre>let user = {<br>  name: &quot;John&quot;<br>};<br><br>Object.preventExtensions(user);<br><br>user.cc=&quot;ali&quot; // it wont allow us to add a new property</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/seal">Object.seal(obj)</a> : forbid adding and removing of properties. Sets configurable: false for all existing properties.</p><pre>let user = {<br>  name: &quot;John&quot;<br>};<br><br>Object.seal(user);<br><br>user.cc=&quot;ali&quot; // it wont allow us to add a new property<br>delete user.name;  // it is impossible to remove</pre><p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze">Object.freeze(obj)</a> : forbids adding/removing/changing of the properties.<br>Sets configurable: false, writable: false for all existing properties.</p><pre>let user = {<br>  name: &quot;John&quot;<br>};<br><br>Object.freeze(user);<br>user.name=&quot;fff&quot;; // &quot;name&quot; property wont be effected and changed<br>user.cc=&quot;ali&quot; // it wont allow us to add a new property<br>delete user.name;  // it is impossible to remove</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c991978f792" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Strings]]></title>
            <link>https://canavci.medium.com/strings-6b6bbb3b417c?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b6bbb3b417c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[typescript]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Tue, 20 Dec 2022 11:16:07 GMT</pubDate>
            <atom:updated>2022-12-20T11:16:07.653Z</atom:updated>
            <content:encoded><![CDATA[<p>In JavaScript, the textual data is stored as strings. in addition to that the internal format for strings is always UTF-16,<br>strings can be enclosed within single or double quotes</p><h3>Getting a substring</h3><p>There are 3 methods in JavaScript to get a substring: substring, substr and slice.</p><p>str.slice(start [, end])</p><p>returns some part of the string with given start and (but not including) end parameters:</p><pre>let str = &quot;stringify&quot;;<br>alert( str.slice(0, 5) ); // &#39;strin&#39;, the substring from 0 to 5 (not including 5)<br>alert( str.slice(0, 1) ); // &#39;s&#39;, from 0 to 1, but not including 1, so only character at 0</pre><p>if there is no end specified. than it will goes till the end of the string</p><pre>let str = &quot;stringify&quot;;<br>alert( str.slice(2) ); // &#39;ringify&#39;, from the 2nd position till the end</pre><p>Negative values for start/end are also possible. They mean the position is counted from the string end:</p><pre>let str = &quot;stringify&quot;;<br><br>// start at the 4th position from the right, end at the 1st from the right<br>alert( str.slice(-4, -1) ); // &#39;gif&#39;</pre><p>str.substring(start [, end])</p><p>Returns the part of the string <em>between</em> start and end (not including end).</p><p>This is almost the same as slice, but it allows start to be greater than end (in this case it simply swaps start and end values).</p><pre>let str = &quot;stringify&quot;;<br><br>// these are same for substring<br>alert( str.substring(2, 6) ); // &quot;ring&quot;<br>alert( str.substring(6, 2) ); // &quot;ring&quot;<br><br>// ...but not for slice:<br>alert( str.slice(2, 6) ); // &quot;ring&quot; (the same)<br>alert( str.slice(6, 2) ); // &quot;&quot; (an empty string)</pre><p>Negative arguments are (unlike slice) not supported, they are treated as 0.</p><p>str.substr(start [, length])</p><p>Returns the part of the string from start, with the given length.<br>this one allows us to specify the length instead of the ending position:</p><pre>let str = &quot;stringify&quot;;<br>alert( str.substr(2, 4) ); // &#39;ring&#39;, from the 2nd position get 4 characters</pre><p>The first argument may be negative, to count from the end:</p><pre>let str = &quot;stringify&quot;;<br>alert( str.substr(-4, 2) ); // &#39;gi&#39;, from the 4th position get 2 characters</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b6bbb3b417c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scroll event]]></title>
            <link>https://canavci.medium.com/scroll-event-8efd82b7dfa3?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8efd82b7dfa3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[dom]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 15:52:55 GMT</pubDate>
            <atom:updated>2022-12-14T15:52:55.717Z</atom:updated>
            <content:encoded><![CDATA[<p>Dom elements have their current scroll state in their scrollLeft/scrollTop properties.</p><p><strong>document.documentElement.scrollLeft/scrollTop</strong> works in most browsers<br>Luckily, we dont have to remember this verbose at all</p><pre>alert(&#39;Current scroll from the top: &#39; + window.pageYOffset);<br>alert(&#39;Current scroll from the left: &#39; + window.pageXOffset);</pre><p>regular elements can be scrolled by changing <strong>scrollTop/scrollLeft.<br></strong>Alternativelt there is a simpler and universal method exists <br><a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollBy">window.scrollBy(x,y)</a> : scrolls the page relative to its current position <a href="https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollTo">window.scrollTo(pageX,pageY)</a> : scrolls the page <em>to absolute coordinates</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8efd82b7dfa3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Element size and scrolling]]></title>
            <link>https://canavci.medium.com/element-size-and-scrolling-116963bbad4d?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/116963bbad4d</guid>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[dom]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Wed, 14 Dec 2022 08:04:06 GMT</pubDate>
            <atom:updated>2022-12-14T08:04:06.851Z</atom:updated>
            <content:encoded><![CDATA[<p>here is the general overview of the geometry about an element size</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nUsDh8MwI1FzBFyOmy7Xew.png" /></figure><p><strong>offsetWidth/Height</strong> : They provide the “outer” width/height of the element. Or, in other words, its full size including borders</p><p><strong>clientTop/Left: </strong>Inside the element we have the borders. in order to measure them we have pharesed used</p><p><strong>clientWidth/Height</strong> : these properties provide the size of area inside an element without borders</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*mcmGn_afcCVcYkAKGLA48A.png" /></figure><p><strong>scrollWidth/Height :</strong> These properties are like clientWidth/clientHeight, but they also include the scrolled out (hidden) parts:</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=116963bbad4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[className and classList]]></title>
            <link>https://canavci.medium.com/classname-and-classlist-b982c5fffadc?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/b982c5fffadc</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Mon, 12 Dec 2022 19:44:49 GMT</pubDate>
            <atom:updated>2022-12-12T19:44:49.702Z</atom:updated>
            <content:encoded><![CDATA[<p>changing the class one of the most often used methods in js. the <strong>elemt.className</strong> corresponds to the “<strong>class</strong>” attribute</p><pre>&lt;body class=&quot;main page&quot;&gt;<br>  &lt;script&gt;<br>    alert(document.body.className); // main page<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><p>if we assign something to <strong>elem.className</strong>. it replace the whole string of classes. sometimes that is what we need. from time to time we want to add/remove a single class rather than completely changing.</p><p>the <strong>elem.classList</strong> is a special object with methods to add/remove/toggle a single class.</p><pre>&lt;body class=&quot;main page&quot;&gt;<br>  &lt;script&gt;<br>    // add a class<br>    document.body.classList.add(&#39;article&#39;);<br>    alert(document.body.className); // main page article<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><p>Methods of classList:<br>elem.classList.add/remove(&quot;class&quot;) – adds/removes the class.</p><ul><li>elem.classList.toggle(&quot;class&quot;) – adds the class if it doesn’t exist, otherwise removes it.</li><li>elem.classList.contains(&quot;class&quot;) – checks for the given class, returns true/false.</li></ul><p>Besides, classList is iterable, so we can list all classes with for..of, like this:</p><pre>&lt;body class=&quot;main page&quot;&gt;<br>  &lt;script&gt;<br>    for (let name of document.body.classList) {<br>      alert(name); // main, and then page<br>    }<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><h3>Element style</h3><p>The property elem.style is an object that corresponds to what’s written in the &quot;style&quot; attribute . Setting elem.style.width=&quot;100px&quot; works the same as if we had in the attribute style a string width:100px.</p><p>Also there is a special method for that, elem.style.removeProperty(&#39;style property&#39;). So, We can remove a property like this:</p><pre>document.body.style.background = &#39;red&#39;; //set background to red<br><br>setTimeout(() =&gt; document.body.style.removeProperty(&#39;background&#39;), 1000); </pre><p>modifying a style is easy. But how to <em>read</em> it?<br>For instance, we want to know the size, margins, the color of an element. How to do it?<br>So we can’t read anything that comes from CSS classes using elem.style</p><p>There’s another method for that: getComputedStyle.</p><pre>&lt;head&gt;<br>  &lt;style&gt; body { color: red; margin: 5px } &lt;/style&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;script&gt;<br>    let computedStyle = getComputedStyle(document.body);<br>    // now we can read the margin and the color from it<br>    alert( computedStyle.marginTop ); // 5px<br>    alert( computedStyle.color ); // rgb(255, 0, 0)<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b982c5fffadc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HTML attributes]]></title>
            <link>https://canavci.medium.com/html-attributes-562a5a1f66a3?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/562a5a1f66a3</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[dom]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Tue, 06 Dec 2022 09:29:52 GMT</pubDate>
            <atom:updated>2022-12-06T09:29:52.491Z</atom:updated>
            <content:encoded><![CDATA[<p>So when an element has id or another <em>standard</em> attribute, the corresponding property gets created. But that doesn’t happen if the attribute is non-standard.</p><pre>&lt;body id=&quot;test&quot; something=&quot;non-standard&quot;&gt;<br>  &lt;script&gt;<br>    alert(document.body.id); // test<br>    // non-standard attribute does not yield a property<br>    alert(document.body.something); // undefined<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><p>note that a standard attribute for one element can be unknown for another one. For instance, &quot;type&quot; is standard for &lt;input&gt; (<a href="https://html.spec.whatwg.org/#htmlinputelement">HTMLInputElement</a>), but not for &lt;body&gt;</p><pre>&lt;body id=&quot;body&quot; type=&quot;...&quot;&gt;<br>  &lt;input id=&quot;input&quot; type=&quot;text&quot;&gt;<br>  &lt;script&gt;<br>    alert(input.type); // text<br>    alert(body.type); // undefined: DOM property not created, because it&#39;s non-standard<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><p>All attributes are accessible by using the following methods:</p><ul><li>elem.hasAttribute(name) – checks for existence.</li><li>elem.getAttribute(name) – gets the value.</li><li>elem.setAttribute(name, value) – sets the value.</li><li>elem.removeAttribute(name) – removes the attribute.</li></ul><pre>&lt;body something=&quot;non-standard&quot;&gt;<br>  &lt;script&gt;<br>    alert(document.body.getAttribute(&#39;something&#39;)); // non-standard<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><h3><a href="https://javascript.info/dom-attributes-and-properties#dom-properties-are-typed">DOM properties are typed</a></h3><p>DOM properties are mostly strings. whereas some attributes may differ, <br>the input.checked property is a boolean:</p><pre>&lt;input id=&quot;input&quot; type=&quot;checkbox&quot; checked&gt; checkbox<br>&lt;script&gt;<br>  alert(input.getAttribute(&#39;checked&#39;)); // the attribute value is: empty string<br>  alert(input.checked); // the property value is: true<br>&lt;/script&gt;</pre><p>There are other examples. The style attribute is a string, but the style property is an object:</p><pre>&lt;div id=&quot;div&quot; style=&quot;color:red;font-size:120%&quot;&gt;Hello&lt;/div&gt;<br>&lt;script&gt;<br>  // string<br>  alert(div.getAttribute(&#39;style&#39;)); // color:red;font-size:120%<br>  // object<br>  alert(div.style); // [object CSSStyleDeclaration]<br>  alert(div.style.color); // red<br>&lt;/script&gt;</pre><h3>Non-standard attributes, dataset</h3><p>Sometimes non-standard attributes are used to pass custom data from HTML to JavaScript, or to “mark” HTML-elements for JavaScript.</p><pre>&lt;!-- mark the div to show &quot;name&quot; here --&gt;<br>&lt;div show-info=&quot;name&quot;&gt;&lt;/div&gt;<br>&lt;!-- and age here --&gt;<br>&lt;div show-info=&quot;age&quot;&gt;&lt;/div&gt;<br><br>&lt;script&gt;<br>  // the code finds an element with the mark and shows what&#39;s requested<br>  let user = { name: &quot;Pete&quot;,   age: 22  };<br>  for(let div of document.querySelectorAll(&#39;[show-info]&#39;)) {<br>    // insert the corresponding info into the field<br>    let field = div.getAttribute(&#39;show-info&#39;);<br>    div.innerHTML = user[field]; // first Pete into &quot;name&quot;, then 25 into &quot;age&quot;<br>  }<br>&lt;/script&gt;</pre><p>Also they can be used to style an element.</p><pre>&lt;style&gt;<br>  /* styles rely on the custom attribute &quot;order-state&quot; */<br>  .order[order-state=&quot;new&quot;] {<br>    color: green;<br>  }<br>  .order[order-state=&quot;pending&quot;] {<br>    color: blue;<br>  }<br>  .order[order-state=&quot;canceled&quot;] {<br>    color: red;<br>  }<br>&lt;/style&gt;<br><br>&lt;div class=&quot;order&quot; order-state=&quot;new&quot;&gt;<br>  A new order.<br>&lt;/div&gt;<br>&lt;div class=&quot;order&quot; order-state=&quot;pending&quot;&gt;<br>  A pending order.<br>&lt;/div&gt;<br>&lt;div class=&quot;order&quot; order-state=&quot;canceled&quot;&gt;<br>  A canceled order.<br>&lt;/div&gt;</pre><p>But there may be a possible problem with custom attributes.<br>To avoid conflicts, there exist <strong>data</strong>-* attributes.</p><p>All attributes starting with “<strong>data</strong>-” are reserved for programmers’ use. They are available in the <strong>dataset</strong> property.</p><pre>&lt;body data-about=&quot;Elephants&quot;&gt;<br>&lt;script&gt;<br>  alert(document.body.dataset.about); // Elephants<br>&lt;/script&gt;</pre><p>Multiword attributes like data-order-state become camel-cased: dataset.orderState.</p><p>Here’s a rewritten “order state” example:</p><pre>&lt;style&gt;<br>  .order[data-order-state=&quot;new&quot;] {<br>    color: green;<br>  }<br><br>  .order[data-order-state=&quot;pending&quot;] {<br>    color: blue;<br>  }<br><br>  .order[data-order-state=&quot;canceled&quot;] {<br>    color: red;<br>  }<br>&lt;/style&gt;<br><br>&lt;div id=&quot;order&quot; class=&quot;order&quot; data-order-state=&quot;new&quot;&gt;<br>  A new order.<br>&lt;/div&gt;<br><br>&lt;script&gt;<br>  // read<br>  alert(order.dataset.orderState); // new<br><br>  // modify<br>  order.dataset.orderState = &quot;pending&quot;; // (*)<br>&lt;/script&gt;</pre><p>Using data-* attributes is a valid, safe way to pass custom data.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=562a5a1f66a3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Node properties — episode -2]]></title>
            <link>https://canavci.medium.com/node-properties-episode-2-8ec7aabab658?source=rss-417b53a4256c------2</link>
            <guid isPermaLink="false">https://medium.com/p/8ec7aabab658</guid>
            <category><![CDATA[javascript-tips]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Can Avcı]]></dc:creator>
            <pubDate>Sun, 04 Dec 2022 19:09:17 GMT</pubDate>
            <atom:updated>2022-12-04T19:09:17.173Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Node properties — episode -2</strong></h3><p>if you didn’t read the first episode i recommend visiting that then return here. otherwise there might be some questions left hanging .</p><h3><a href="https://javascript.info/basic-dom-node-properties#nodevalue-data-text-node-content">nodeValue vs data</a></h3><p>while The innerHTML property is only valid for element nodes.<br>Other node types, such as text nodes, have their counterparts such as nodeValue and data properties. these both performs the same task as the “innerHtml” have done.</p><pre>&lt;body&gt;<br>  Hello<br>  &lt;!-- Comment --&gt;<br>  &lt;script&gt;<br>    let text = document.body.firstChild;<br>    alert(text.data); // Hello<br><br>    let comment = text.nextSibling;<br>    alert(comment.data); // Comment<br>  &lt;/script&gt;<br>&lt;/body&gt;</pre><h3>textContent: pure text</h3><p>The textContent provides access to get the <em>text</em> inside a given element:</p><pre>&lt;div id=&quot;news&quot;&gt;<br>  &lt;h1&gt;Headline!&lt;/h1&gt;<br>  &lt;p&gt;Martians attack people!&lt;/p&gt;<br>&lt;/div&gt;<br><br>&lt;script&gt;<br>  // Headline! Martians attack people!<br>  alert(news.textContent);<br>&lt;/script&gt;</pre><h3>The “hidden” property</h3><p>The “hidden” attribute and the DOM property specifies whether the element is visible or not.</p><pre>&lt;div&gt;Both divs below are hidden&lt;/div&gt;<br><br>&lt;div hidden&gt;With the attribute &quot;hidden&quot;&lt;/div&gt;<br><br>&lt;div id=&quot;elem&quot;&gt;JavaScript assigned the property &quot;hidden&quot;&lt;/div&gt;<br><br>&lt;script&gt;<br>  elem.hidden = true;<br>&lt;/script&gt;</pre><p>Technically, hidden works the same as style=&quot;display:none&quot;. But it’s shorter to write.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8ec7aabab658" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>