<?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: Marko Zivkovic</title>
    <description>The latest articles on DEV Community by Marko Zivkovic (@sdzika).</description>
    <link>https://dev.to/sdzika</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%2F1936458%2Fa9eaa291-4c7b-4c2f-94ed-feeb5851ef22.jpeg</url>
      <title>DEV Community: Marko Zivkovic</title>
      <link>https://dev.to/sdzika</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sdzika"/>
    <language>en</language>
    <item>
      <title>Demystifying Regular Expressions: A Quick Guide</title>
      <dc:creator>Marko Zivkovic</dc:creator>
      <pubDate>Fri, 16 Aug 2024 06:18:44 +0000</pubDate>
      <link>https://dev.to/sdzika/demystifying-regular-expressions-a-quick-guide-247n</link>
      <guid>https://dev.to/sdzika/demystifying-regular-expressions-a-quick-guide-247n</guid>
      <description>&lt;p&gt;Regular expressions, often abbreviated as regex, are powerful tools used in programming for pattern matching and manipulation of text. They provide a concise and flexible way to search, match, and replace text based on specific patterns.&lt;/p&gt;

&lt;h2&gt;
  
  
  What are Regular Expressions?
&lt;/h2&gt;

&lt;p&gt;Regular expressions are sequences of characters that define a search pattern. They are used in various programming languages and tools for tasks such as validation, searching, and string manipulation. Here’s a simple regex example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const regex = /hello/;
const text = "hello world";
console.log(regex.test(text)); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In the example above, the regex /hello/ searches for the word "hello" in the given text.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Syntax
&lt;/h2&gt;

&lt;p&gt;Regex syntax can be simple or complex depending on the pattern you want to define. Here are a few basic components:&lt;/p&gt;

&lt;p&gt;Literal Characters: Match the exact characters. E.g., /abc/ matches "abc".&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Character Classes: Match any character within the brackets. E.g., /[a-z]/ matches any lowercase letter.&lt;/li&gt;
&lt;li&gt;Quantifiers: Specify the number of times a character or group should be matched. E.g., /a{2,4}/ matches "aa", "aaa", or "aaaa".&lt;/li&gt;
&lt;li&gt;Anchors: Match positions in a string. E.g., /^abc/ matches "abc" at the beginning of a string.&lt;/li&gt;
&lt;li&gt;Groups and Ranges: Define groups or ranges of characters. E.g., /(abc|def)/ matches "abc" or "def".&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Practical Applications
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Validation: Regular expressions are commonly used to validate user input, such as email addresses or phone numbers.&lt;/li&gt;
&lt;li&gt;Search and Replace: Easily find and replace text patterns in a string.&lt;/li&gt;
&lt;li&gt;Parsing: Extract specific data from a large text body.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Example: Email Validation
&lt;/h2&gt;

&lt;p&gt;Here’s a simple regex for validating email addresses:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
const email = "example@example.com";
console.log(emailRegex.test(email)); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Regular expressions are incredibly useful for developers and are widely used across different domains. While they may seem daunting at first, mastering regex can greatly enhance your ability to manipulate and analyze text.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Harnessing the Power of the useState Hook in React</title>
      <dc:creator>Marko Zivkovic</dc:creator>
      <pubDate>Fri, 16 Aug 2024 06:12:34 +0000</pubDate>
      <link>https://dev.to/sdzika/harnessing-the-power-of-the-usestate-hook-in-react-1l94</link>
      <guid>https://dev.to/sdzika/harnessing-the-power-of-the-usestate-hook-in-react-1l94</guid>
      <description>&lt;p&gt;React hooks have revolutionized how we manage state in functional components. Among these hooks, useState is perhaps the most fundamental and widely used. It allows you to add state to functional components, making them more dynamic and interactive.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introduction to useState
&lt;/h2&gt;

&lt;p&gt;The useState hook is a special function that lets you manage state in a functional component. You can use it to declare a state variable and a function to update that variable.&lt;/p&gt;

&lt;p&gt;Here's the basic syntax:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import React, { useState } from 'react';function ExampleComponent() {&lt;br&gt;
  const [stateVariable, setStateVariable] = useState(initialValue);&lt;br&gt;
  // Component logic and JSX return&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;stateVariable: The current state value.&lt;br&gt;
setStateVariable: A function that lets you update the state.&lt;br&gt;
initialValue: The initial state value, which can be of any data type (string, number, array, object, etc.).&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;Let’s walk through a simple example where we use useState to manage a counter.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;import React, { useState } from 'react';&lt;br&gt;
function Counter() {&lt;br&gt;
  const [count, setCount] = useState(0);&lt;br&gt;
  const increment = () =&amp;gt; {&lt;br&gt;
    setCount(count + 1);&lt;br&gt;
  };&lt;br&gt;
  const decrement = () =&amp;gt; {&lt;br&gt;
    setCount(count - 1);&lt;br&gt;
  };&lt;br&gt;
  return (&lt;br&gt;
    &amp;lt;div&amp;gt;&lt;br&gt;
      &amp;lt;p&amp;gt;Current count: {count}&amp;lt;/p&amp;gt;&lt;br&gt;
      &amp;lt;button onClick={increment}&amp;gt;Increment&amp;lt;/button&amp;gt;&lt;br&gt;
      &amp;lt;button onClick={decrement}&amp;gt;Decrement&amp;lt;/button&amp;gt;&lt;br&gt;
    &amp;lt;/div&amp;gt;&lt;br&gt;
  );&lt;br&gt;
}&lt;br&gt;
export default Counter;&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Updating State
&lt;/h2&gt;

&lt;p&gt;When you call the state update function (e.g., setCount), React schedules a re-render of the component. During the next render, useState returns the updated state value.&lt;/p&gt;

&lt;p&gt;Here are a few things to keep in mind:&lt;br&gt;
State Updates are Asynchronous: React batches multiple state updates for performance. This means that the state might not update immediately after calling the setter function.&lt;br&gt;
Functional Updates: When updating state based on the previous state, use the functional update form to ensure you have the latest state.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;setCount((prevCount) =&amp;gt; prevCount + 1);&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Multiple State Variables
&lt;/h2&gt;

&lt;p&gt;You can use useState multiple times in a single component to manage different pieces of state.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;function Profile() {&lt;br&gt;
  const [name, setName] = useState('John Doe');&lt;br&gt;
  const [age, setAge] = useState(30);&lt;br&gt;
  // Component logic and JSX return&lt;br&gt;
}&lt;/code&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The useState hook is a powerful tool for managing state in React functional components. Its simplicity and flexibility make it a go-to solution for local state management. By understanding how to effectively use useState, you can build responsive and interactive user interfaces with ease.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mastering the sort() Method in JavaScript</title>
      <dc:creator>Marko Zivkovic</dc:creator>
      <pubDate>Fri, 16 Aug 2024 06:07:25 +0000</pubDate>
      <link>https://dev.to/sdzika/mastering-the-sort-method-in-javascript-4ef3</link>
      <guid>https://dev.to/sdzika/mastering-the-sort-method-in-javascript-4ef3</guid>
      <description>&lt;p&gt;Sorting data is a fundamental operation in programming, and JavaScript provides a powerful built-in method to handle this: the sort() method. Whether you're dealing with numbers, strings, or complex objects, sort() can help you organize your data efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Basic Usage
&lt;/h2&gt;

&lt;p&gt;The sort() method sorts the elements of an array in place and returns the sorted array. By default, it sorts elements as strings in ascending order.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const fruits = ['banana', 'apple', 'cherry'];&lt;br&gt;
fruits.sort();&lt;br&gt;
console.log(fruits); // Output: ['apple', 'banana', 'cherry']&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Sorting Numbers
&lt;/h2&gt;

&lt;p&gt;One common pitfall with sort() is its behavior with numbers. Since it converts elements to strings, sorting numbers directly can lead to unexpected results.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const numbers = [10, 5, 20, 15];&lt;br&gt;
numbers.sort();&lt;br&gt;
console.log(numbers); // Output: [10, 15, 20, 5]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To sort numbers correctly, you need to provide a comparison function:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;numbers.sort((a, b) =&amp;gt; a - b);&lt;br&gt;
console.log(numbers); // Output: [5, 10, 15, 20]&lt;br&gt;
The comparison function should return a negative value if the first argument is less than the second, zero if they're equal, and a positive value otherwise.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Sorting Strings
&lt;/h2&gt;

&lt;p&gt;Sorting strings in JavaScript is straightforward since the default behavior of sort() is suited for string sorting. However, for case-insensitive sorting or sorting based on locale, you might need to tweak the comparison function.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const animals = ['elephant', 'Zebra', 'giraffe'];&lt;br&gt;
animals.sort((a, b) =&amp;gt; a.localeCompare(b));&lt;br&gt;
console.log(animals); // Output: ['elephant', 'giraffe', 'Zebra']&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Sorting Objects
&lt;/h2&gt;

&lt;p&gt;When dealing with arrays of objects, you must specify how to compare the objects by their properties.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;const people = [&lt;br&gt;
  { name: 'Alice', age: 30 },&lt;br&gt;
  { name: 'Bob', age: 25 },&lt;br&gt;
  { name: 'Charlie', age: 35 }&lt;br&gt;
];&lt;br&gt;
people.sort((a, b) =&amp;gt; a.age - b.age);&lt;br&gt;
console.log(people);&lt;br&gt;
// Output: [&lt;br&gt;
//   { name: 'Bob', age: 25 },&lt;br&gt;
//   { name: 'Alice', age: 30 },&lt;br&gt;
//   { name: 'Charlie', age: 35 }&lt;br&gt;
// ]&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The sort() method is a versatile tool in JavaScript, capable of handling a variety of data types and sorting needs. By mastering its use and understanding how to craft comparison functions, you can leverage its power to keep your data organized and accessible.&lt;/p&gt;

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