<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Hemanth Kumar R</title>
    <description>The latest articles on DEV Community by Hemanth Kumar R (@hemanth60505431).</description>
    <link>https://dev.to/hemanth60505431</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F660208%2F0933bfde-a070-4f8a-9d08-4f13b5c58034.png</url>
      <title>DEV Community: Hemanth Kumar R</title>
      <link>https://dev.to/hemanth60505431</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hemanth60505431"/>
    <language>en</language>
    <item>
      <title>Loops in javascript</title>
      <dc:creator>Hemanth Kumar R</dc:creator>
      <pubDate>Sat, 16 Oct 2021 05:45:19 +0000</pubDate>
      <link>https://dev.to/hemanth60505431/loops-in-javascript-29gd</link>
      <guid>https://dev.to/hemanth60505431/loops-in-javascript-29gd</guid>
      <description>&lt;p&gt;Loops are used in JavaScript to perform repeated tasks based on a condition. Conditions typically return true or false when analysed. A loop will continue running until the defined condition  returns false.&lt;/p&gt;

&lt;p&gt;The three most common types of loops are&lt;br&gt;
• for&lt;br&gt;
• while&lt;br&gt;
• do while&lt;/p&gt;

&lt;p&gt;for loop&lt;/p&gt;

&lt;p&gt;Syntax&lt;/p&gt;

&lt;p&gt;for ([initialization]; [condition]; [final-expression]) {&lt;br&gt;
   // statement&lt;br&gt;
}&lt;/p&gt;

&lt;p&gt;The javascript for statement consists of three expressions and a statement:&lt;br&gt;
Description&lt;br&gt;
• Initialization - Run before the first execution on the loop. This expression is commonly used to create counters. Variables created here are scoped to the loop. Once the loop has finished it’s execution they are destroyed.&lt;br&gt;
• Condition - Expression that is checked prior to the execution of every iteration. If omitted, this expression evaluates to true. If it evaluates to true, the loop’s statement is executed. If it evaluates to false, the loop stops.&lt;br&gt;
• Final-expression - Expression that is run after every iteration. Usually used to increment a counter. But it can be used to decrement a counter too.&lt;br&gt;
• statement - Code to be repeated in the loop&lt;br&gt;
any of these three expressions or the statement can be omitted. For loops are commonly used to count a certain number of iterations to repeat a statement. Use a break statement to exit the loop before the condition expression evaluates to false.&lt;br&gt;
Common Pitfalls&lt;br&gt;
Exceeding the bounds of an array&lt;br&gt;
When indexing over an array many times it is easy to exceed the bounds of the array (ex. try to reference the 4th element of a 3 element array).&lt;br&gt;
      // This will cause an error.&lt;br&gt;
          // The bounds of the array will be exceeded.&lt;br&gt;
        var arr = [ 1, 2, 3 ];&lt;br&gt;
        for (var i = 0; i &amp;lt;= arr.length; i++) {&lt;br&gt;
        console.log(arr[i]);&lt;br&gt;
        }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    output:
    1
    2
    3
    undefined
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;There are two ways to fix this code. Set the condition to either i &amp;lt; arr.length or i &amp;lt;= arr.length - 1&lt;br&gt;
Examples&lt;br&gt;
Iterate through integers from 0-8&lt;br&gt;
    for (var i = 0; i &amp;lt; 9; i++) {&lt;br&gt;
    console.log(i);&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output:
0
1
2
3
4
5
6
7
8
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Break out of a loop before condition expression is false&lt;br&gt;
    for (var elephant = 1; elephant &amp;lt; 10; elephant+=2) {&lt;br&gt;
       if (elephant === 7) {&lt;br&gt;
                break;&lt;br&gt;
        }&lt;br&gt;
        console.info('elephant is ' + elephant);&lt;br&gt;
    }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;output:
elephant is 1
elephant is 3
elephant is 5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;for...in loop&lt;br&gt;
The for...in statement iterates over the enumerable properties of an object, in arbitrary order. For each distinct property, statements can be executed.&lt;br&gt;
    for (variable in object) {&lt;br&gt;
    ...&lt;br&gt;
    }&lt;br&gt;
Required/OptionalParameterDescriptionRequiredVariableA different property name is assigned to variable on each iteration.OptionalObjectObject whose enumerable properties are iterated.&lt;br&gt;
Examples&lt;br&gt;
    // Initialize object.&lt;br&gt;
    a = { "a": "Athens", "b": "Belgrade", "c": "Cairo" }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Iterate over the properties.
var s = ""
for (var key in a) {
  s += key + ": " + a[key];
 s += "&amp;lt;br /&amp;gt;";
  }
document.write (s);

// Output:
// a: Athens
// b: Belgrade
// c: Cairo

// Initialize the array.
var arr = new Array("zero", "one", "two");

// Add a few expando properties to the array.
arr["orange"] = "fruit";
arr["carrot"] = "vegetable";

// Iterate over the properties and elements.
var s = "";
for (var key in arr) {
 s += key + ": " + arr[key];
 s += "&amp;lt;br /&amp;gt;";
}

document.write (s);

// Output:
//   0: zero
//   1: one
//   2: two
//   orange: fruit
//   carrot: vegetable

// Efficient way of getting an object's keys using an expression within    the for-in loop's conditions
var myObj = {a: 1, b: 2, c:3}, myKeys = [], i=0;
for (myKeys[i++] in myObj);

document.write(myKeys);

//Output:
//   a
//   b
//   c
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;for...of loop&lt;br&gt;
The for...of statement creates a loop iterating over iterable objects (including Array, Map, Set, Arguments object and so on), invoking a custom iteration hook with statements to be executed for the value of each distinct property.&lt;br&gt;
    for (variable of object) {&lt;br&gt;
        statement&lt;br&gt;
    }&lt;br&gt;
DescriptionvariableOn each iteration a value of a different property is assigned to variable.objectObject whose enumerable properties are iterated.&lt;br&gt;
 Examples&lt;br&gt;
 Array&lt;br&gt;
     let arr = [ "fred", "tom", "bob" ];&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; for (let i of arr) {
     console.log(i);
 }

 // Output:
 // fred
 // tom
 // bob
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Map&lt;br&gt;
      var m = new Map();&lt;br&gt;
       m.set(1, "black");&lt;br&gt;
       m.set(2, "red");&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; for (var n of m) {
     console.log(n);
  }

 // Output:
 // 1,black
 // 2,red
 Set
  var s = new Set();
  s.add(1);
  s.add("red");

  for (var n of s) {
     console.log(n);
   }

  // Output:
  // 1
  // red
Arguments object
 // your browser must support for..of loop
 // and let-scoped variables in for loops

  function displayArgumentsObject() {
      for (let n of arguments) {
         console.log(n);
       }
    }


  displayArgumentsObject(1, 'red');

   // Output:
   // 1
   // red
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;while loop&lt;br&gt;
The while loop starts by evaluating the condition. If the condition is true, the statement(s) is/are executed. If the condition is false, the statement(s) is/are not executed. After that, while loop ends.&lt;br&gt;
Here is the syntax for while loop:&lt;br&gt;
Syntax:&lt;br&gt;
    while (condition)&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{

 statement(s);

}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;statement(s): A statement that is executed as long as the condition evaluates to true.&lt;br&gt;
condition: Here, condition is a Boolean expression which is evaluated before each pass through the loop. If this condition evaluates to true, statement(s) is/are executed. When condition evaluates to false, execution continues with the statement after the while loop.&lt;br&gt;
Example:&lt;br&gt;
     var i = 1;&lt;br&gt;
        while (i &amp;lt; 10) &lt;br&gt;
        {&lt;br&gt;
         console.log(i);&lt;br&gt;
         i++; // i=i+1 same thing&lt;br&gt;
        }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    Output:
    1 
    2 
    3 
    4
    5
    6
    7
    8
    9
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;How to Iterate with JavaScript While Loops&lt;br&gt;
While loops will run as long as the condition inside the ( ) is true. Example:&lt;br&gt;
    while(condition){&lt;br&gt;
    code...&lt;br&gt;
    }&lt;br&gt;
Hint 1:&lt;br&gt;
Use a iterator variable such as i in your condition&lt;br&gt;
    var i = 0;&lt;br&gt;
    while(i &amp;lt;= 4){&lt;br&gt;
    }&lt;br&gt;
Spoiler Alert Solution Ahead!&lt;br&gt;
Solution:&lt;br&gt;
    // Setup&lt;br&gt;
    var myArray = [];&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Only change code below this line.
var i = 0;
while (i &amp;lt;= 4){
  myArray.push(i);
  i++;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Do...while loop&lt;br&gt;
The do...while loop is closely related to while loop. In the do while loop, the condition is checked at the end of the loop.&lt;br&gt;
Here is the syntax for do...while loop:&lt;br&gt;
        Syntax:&lt;br&gt;
    do {&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  *Statement(s);*

} while (*condition*);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;statement(s): A statement that is executed at least once before the condition or Boolean expression is evaluated and is re-executed each time the condition evaluates to true.&lt;br&gt;
condition: Here, a condition is a Boolean expression. If Boolean expression evaluates to true, the statement is executed again. When Boolean expression evaluates to false, the loops ends.&lt;br&gt;
Example:&lt;br&gt;
    var i = 0;&lt;br&gt;
    do {&lt;br&gt;
     i = i + 1;&lt;br&gt;
     console.log(i);&lt;br&gt;
    } while (i &amp;lt; 5);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Output:
1
2
3
4
5
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;How to Iterate with JavaScript Do…While Loops&lt;br&gt;
• Do...While loops makes sure that the code is executed at least once, and after the execution, if the condition inside the while() is true, it continues with the loop, otherwise it stop.&lt;br&gt;
Solution:&lt;br&gt;
    var myArray = [];&lt;br&gt;
    var i = 10;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;do {
 myArray.push(i);
 i++;
} while(i &amp;lt;= 10);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

</description>
      <category>javascript</category>
    </item>
    <item>
      <title>Comments in HTML,CSS and JAVASCRIPT</title>
      <dc:creator>Hemanth Kumar R</dc:creator>
      <pubDate>Fri, 15 Oct 2021 17:14:58 +0000</pubDate>
      <link>https://dev.to/hemanth60505431/comments-in-htmlcss-and-javascript-c5j</link>
      <guid>https://dev.to/hemanth60505431/comments-in-htmlcss-and-javascript-c5j</guid>
      <description>&lt;p&gt;Single line HTML comments&lt;br&gt;
To comment out a single line of HTML, place the text or code you are commenting between comment tags: &amp;lt;!-- --&amp;gt;.&lt;/p&gt;

&lt;p&gt;Here’s how this looks in the code:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;!-- The text in here will be invisible on the website --&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Here's some regular HTML content!&lt;/p&gt;

&lt;p&gt;When you load the website, the HTML comment won’t show up on the page itself:&lt;/p&gt;

&lt;p&gt;Website showing text content but not the HTML comment&lt;br&gt;
But if you inspect the website code in your browser, you will still be able to see the HTML comment text:&lt;/p&gt;

&lt;p&gt;Code inspector in the browser showing the comment&lt;br&gt;
Multiline HTML comments&lt;br&gt;
To create a multiline or block HTML comment, you still use the comment (&amp;lt;!-- --&amp;gt;) tags, but you can have more than one line in your comment. As long as you contain the comment text between the tags, it will be included in the comment.&lt;/p&gt;

&lt;p&gt;Here’s an example of a multiline HTML comment:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;!-- 
  The text in here will be invisible on the website!
   Here's another line of the comment.
   You can have as many lines as you want! 😁
--&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;And here's that regular HTML content again.&lt;/p&gt;

&lt;p&gt;Here’s how it will look on the website:&lt;/p&gt;

&lt;p&gt;Website text without HTML comment showing&lt;br&gt;
And you can see the whole HTML comment in the inspector:&lt;/p&gt;

&lt;p&gt;Browser inspector showing the multiline HTML comment&lt;br&gt;
How to write comments in CSS&lt;br&gt;
Single line CSS comments&lt;br&gt;
To make a single line CSS comment, put the comment text or code between /* */tags.&lt;/p&gt;

&lt;p&gt;Here’s an example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   /* This text will be ignored by the browser! */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;.description {&lt;br&gt;
  font-size: 1rem;&lt;br&gt;
  line-height: 1.25rem;&lt;br&gt;
  color: #202020;&lt;br&gt;
}&lt;br&gt;
Multiline CSS comments&lt;br&gt;
To write multiline or block CSS comments, you can use the same /* */ tags, and put the comment content on multiple lines.&lt;/p&gt;

&lt;p&gt;Here’s what a multiline CSS comment would look like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   /* 
    This text will be ignored by the browser! 
    And this will also be included in the comment!
    One last line of comment for good measure 😁
   */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;.description {&lt;br&gt;
  font-size: 1rem;&lt;br&gt;
  line-height: 1.25rem;&lt;br&gt;
  color: #202020;&lt;br&gt;
}&lt;br&gt;
How to write comments in JavaScript&lt;br&gt;
Single line JavaScript comments&lt;br&gt;
To create a single line comment in JavaScript, begin the line with two forward slashes (//).&lt;/p&gt;

&lt;p&gt;Here’s an example of that:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     // This text is a comment and will be ignored!
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You can also add a single line comment on the same line as some code. As long as the comment is the last content on that line, it will work.&lt;/p&gt;

&lt;p&gt;Here’s what that would look like:&lt;/p&gt;

&lt;p&gt;console.log('Test code here!'); // This is a console log message&lt;br&gt;
Multiline JavaScript comments&lt;br&gt;
If you want to create a multiline or block comment in JavaScript, enclose the comment text between /* */ tags. (This is the same method as in CSS.)&lt;/p&gt;

&lt;p&gt;Here’s what that will look like:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;     /* 
      Function: doSomeAwesomeThing()
      This does something awesome, but I don't know what! 
    */
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;function doSomeAwesomeThing(){&lt;br&gt;
  console.log('Run awesome function');&lt;br&gt;
}&lt;br&gt;
In closing&lt;br&gt;
Adding comments to your code in HTML, CSS, and JavaScript will help other people to understand what your code is about.&lt;/p&gt;

&lt;p&gt;It’s also helpful when you’re working on a project in development and need to temporarily comment out some code while testing. But just make sure to not leave comments in production code!&lt;/p&gt;

</description>
    </item>
    <item>
      <title>JavaScript working in Leyman words</title>
      <dc:creator>Hemanth Kumar R</dc:creator>
      <pubDate>Tue, 05 Oct 2021 18:21:01 +0000</pubDate>
      <link>https://dev.to/hemanth60505431/javascripting-working-in-leyman-words-25dj</link>
      <guid>https://dev.to/hemanth60505431/javascripting-working-in-leyman-words-25dj</guid>
      <description>&lt;p&gt;How do you think a JavaScript program is executed?&lt;br&gt;
So every browser provides a JavaScript engine that runs the JavaScript code.&lt;br&gt;
there are two methods commonly known, one is where the whole code file is run and transformed to machine language known as Compiled language and the other is a code file  executed line by line also known as interpreted type . so JavaScript is an interpreted language i.e. program is executed sequentially and hence it’s called  single-threaded language at runtime.&lt;/p&gt;

&lt;p&gt;now, JavaScript called a Client-side Scripting Language. That means that it is a computer programming language that runs inside an Internet browser the browser provides JavaScript engine which is a program or an interpreter that executes JavaScript code. A JavaScript engine can be implemented as a standard interpreter, or just-in-time compiler that compiles JavaScript to byte code in some form.&lt;/p&gt;

&lt;p&gt;The way JavaScript works is interesting. Inside a normal Web page you place some JavaScript code . When the browser loads the page, the browser has a built-in interpreter that reads the JavaScript code it finds in the page and runs it.&lt;/p&gt;

&lt;p&gt;The engine used for JavaScript consists of two main components:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Heap Memory— this is where the allocation of memory happens.&lt;br&gt;
Call Stack — this is the place where the stacks are getting called and the code executes. &lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like any other programming language, JavaScript runtime has one stack and one heap storage. A heap is a free memory storage unit where you can store memory in random order. Data that is going to persist in for a considerable amount of time go inside the heap. Heap is managed by the JavaScript runtime and cleaned up by the garbage collector.&lt;br&gt;
What we are interested in is stack. A stack is LIFO (last in, first out) data storage that stores the current function execution context of a program.&lt;/p&gt;

&lt;p&gt;so now imagine a small program consisting of a variable, function and o/p statement now the whole program is executed line by line where the variable encountered is stored separately  in the memory with value undefined (i.e all variables will be recorded in the memory at once that are existing in the whole program )and then next imagine a pointer which points to all different variable numbered sequentially. then when in the same program a function is encountered a separate execution context is created like a sub task and is executed line by line so if a variable is assigned a value in that function then after completing the function the subtask value is stored into the stack above the already existing element in the stack that is the Global Execution context  so this process repeats until there are more functions and the stack is accumulated accordingly. once the end is reached then the stack starts popping out the elements where this elements value is assigned to the  variable in the memory which was earlier undefined and  the process repeats till the stack is empty so all this happens simultaneously .&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Global execution context as an environment where the code runs.&lt;br&gt;
There can be multiple execution context in a program but a single Global execution context. &lt;br&gt;
The stack is cleared after each operation as well as memory after the operation.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Overview&lt;/p&gt;

&lt;p&gt;the program is divided into 3 parts that is the variable part ,the function part and the output part, these are the basic building blocks of a program where all data stored should be outputted at one point of the time. Now variables are stored in memory sequentially and when the function is encountered it is treated as subtask and the execution takes place separately for each function and pushed into the call stack and the value or outcome of that function is stored into stack then the same process completes till the end of the program and then the stack is popped and the associated value is assigned to related variables which were earlier undefined and the memory is erased after the value is outputted.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
