<?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>Forem: Abaid Ullah</title>
    <description>The latest articles on Forem by Abaid Ullah (@abaidbutt).</description>
    <link>https://forem.com/abaidbutt</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%2F1032306%2F59b55bcd-df05-4b2c-9b46-27fcd6ce1a76.jpeg</url>
      <title>Forem: Abaid Ullah</title>
      <link>https://forem.com/abaidbutt</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/abaidbutt"/>
    <language>en</language>
    <item>
      <title>5 Most Important Things in Java Script</title>
      <dc:creator>Abaid Ullah</dc:creator>
      <pubDate>Thu, 18 May 2023 10:12:59 +0000</pubDate>
      <link>https://forem.com/abaidbutt/5-most-important-things-in-java-script-3cpi</link>
      <guid>https://forem.com/abaidbutt/5-most-important-things-in-java-script-3cpi</guid>
      <description>&lt;p&gt;There are five most important things to know for a developer to learn JavaScript.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Variables and Data Types&lt;/li&gt;
&lt;li&gt;Conditional Statement&lt;/li&gt;
&lt;li&gt;Functions&lt;/li&gt;
&lt;li&gt;Objects and Array Methods&lt;/li&gt;
&lt;li&gt;Promises &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Variables and Data Types&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables are used to store and manipulate data. Here we show how to declare a variable and how to assign a value to a variable.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// using var:
var myVariable; // declare a variable in js
myVariable = "Hello, world!"; // assign a value to a variable

// Different methods to declare variable
let myNewVariable;
myNewVariable = "Hi, world!";

const myNewVariable = "Hey, world!";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Data Types&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Variables can store different types of data, such as strings, numbers, booleans, objects, or arrays.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Data Types
let myNumber = 34; // number
let myString = "Hello, World!"; //string
let myBoolean = true; //boolean

let myArray = [1, 2, 3]; // array
let myObject = { name: "Smith", age: 25 }; // object

let myNullValue = null;
let myUndefinedVariable;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conditional Statements in JS&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Conditional Statements help to make decisions and execute specific blocks of code. we use &lt;code&gt;if-else&lt;/code&gt; and &lt;code&gt;switch&lt;/code&gt; for conditional statements in JavaScript.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Conditional Statement
let x = 10; // number
let result = "";
//By using if-else statement
if (x &amp;gt; 5) {
  result = "x is greater";
} else {
  result = "x is less";
}
console.log(result); // Output: 'x is greater'

// else if  statement
if (x &amp;gt; 10) {
  result = "x is greater";
} else if (x == 10) {
  result = "x is Equal";
} else {
  result = "x is less";
}
console.log(result); // Output: 'x is Equal'

// Ternary operator
let result = x &amp;gt; 15 ? "x is greater" : "x is less";
console.log(result); // Output: "x is less"

//Switch Statement
let dayOfWeek = "Monday";
switch (dayOfWeek) {
  case "Monday":
    console.log("Today is Monday");
    break;
  case "Tuesday":
    console.log("Today is Tuesday");
    break;
  default:
    console.log("Invalid day of the week");
}
// Output: 'Today is Monday'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Functions in JavaScript&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Functions in JavaScript work as reusable blocks of code that can be invoked or called to perform a specific task.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;//Functions
** Named Function
function addItems(item1, item2) {
  return item1 + item2;
}
console.log(addItems(2, 4)); // Output : 6

** Anonymous Function

let double = function (num) {
  return num * 3;
};
console.log(double(4)); // Output :8

** Arrow Function
let triple = (num) =&amp;gt; {
  return num * 3;
};
console.log(triple(4)); // Output : 12

** Single Line Function
const f = (a, b) =&amp;gt; a + b;
console.log(f(3, 4)); // Output: 7

** High Order Function
function createFunction() {
  function f(a, b) {
    const sum = a + b;
    return sum;
  }
  return f;
}

const f = createFunction();
console.log(3, 4); // 7

** Immediately Invoked Function Expression (IIFE)

const result = (function (a, b) {
  const sum = a + b;
  return sum;
})(3, 4);
console.log(result); // 7
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Objects and Array Methods&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Objects and arrays are two important data structures used for organizing and manipulating data.&lt;/p&gt;

&lt;p&gt;Arrays are collections of values and it defined using square brackets &lt;code&gt;[]&lt;/code&gt; and contain comma-separated values.&lt;br&gt;
Array indices starting from &lt;code&gt;0&lt;/code&gt; for the first element.&lt;br&gt;
Arrays allow you to store multiple values of any data type in a sequential manner.&lt;br&gt;
&lt;/p&gt;

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

** Array Map Method
const arrMap = [1, 2, 3];
const doubled = arrMap.map((num) =&amp;gt; num * 2);
console.log(doubled); // Output: [2,4,6]

** Array Filter Mathod
const arrFilter = [1, 2, 3, 4, 5];
const evens = arrFilter.filter((num) =&amp;gt; num % 2 === 0);
console.log(evens); // Output: [2,4]

** Array Reduse Method
const arrReduce = [1, 2, 3, 4, 5];
const sum = arrReduce.reduce((acc, num) =&amp;gt; acc + num, 0);
console.log(sum); // Output: 15

** Array Slice Method
const arr = [1, 2, 3, 4, 5];
const sliced = arr.slice(1, 4);
console.log(sliced); // Output: [2,3,4]

** Array Concat Method
const arr1 = [1, 2, 3];
const arr2 = [4, 5, 6];
const combined = arr1.concat(arr2);
console.log(combined); // Output: [1, 2, 3, 4, 5, 6]

** Array ForEach Method
const nums = [1, 2, 3];
nums.forEach((num) =&amp;gt; console.log(num * 2)); // Output: [2, 4, 6]

** Array IndexOf Method
const numb = [1, 2, 3, 2];
const index = numb.indexOf(2);
console.log(index); // Output: 1

** Array Sort Method
const arrSort = [3, 1, 4, 15, 9, 2, 6, 5, 3];
arrSort.sort();
console.log(arrSort); // Output: [1, 1, 2, 3, 3, 4, 5, 5, 6, 9]

** Array Find Method
const arrFind = [1, 2, 3, 4, 5];
const even = arrFind.find((num) =&amp;gt; num % 2 === 0);
console.log(even); // Output: 2

** Array Include Method
const arrInclude = [1, 2, 3];
const hasTwo = arrInclude.includes(2);
console.log(hasTwo); // Output: true

** Array Reverse Method
const arrReverse = [1, 2, 3];
arrReverse.reverse();
console.log(arrReverse); // Output: [3, 2, 1]

** Array Join Method
const arrJoin = [1, 2, 3];
const str = arrJoin.join("-");
console.log(str); // Output: "1-2-3"

** Array UnShift Method
const arrUnShift = [3, 4, 5];
const length = arrUnShift.unshift(1, 2);
console.log(lenght); // Output: 5
console.log(nums); // Output: [1, 2, 3 ,4, 5]

** Array Shift Method
const arrShift = [1, 2, 3];
const first = arrShift.shift();
console.log(first); // Output: 1
console.log(arrShift); // Output: [2, 3]

** Array Push Method
const arrPush = [1, 2];
const length = arrPush.push(3, 4);
console.log(length); // Output: 4
console.log(arrPush); // Output: [1, 2, 3, 4]

** Array  Pop Method
const arrPop = [1, 2, 3];
const last = arrPop.pop();
console.log(last); // Output: 3
console.log(arrPop); // Output: [1, 2]

** Array Splice Method
const arrSplice = [1, 2, 3, 4];
arrSplice.splice(1, 2, 5, 6);
console.log(arrSplice); // Output:[1, 5, 6, 4]

** Array Find Index Method
const arrFindIndex = [1, 2, 3, 4, 5];
const index = arrFindIndex.findIndex((num) =&amp;gt; num % 2 === 0);
console.log(index); // Output: 1

** Array Every Method
const arrEvery = [2, 4, 6];
const isEven = arrEvery.every((num) =&amp;gt; num % 2 === 0);
console.log(isEven); // Output: true

** Array Some Method
const arrSome = [1, 2, 3];
const hasEven = arrSome.some((num) =&amp;gt; num % 2 === 0);
console.log(hasEven); // Output: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Objects In JS&lt;/strong&gt;&lt;br&gt;
we represent objects in key-value pairs inside a curly braces &lt;code&gt;{}&lt;/code&gt;. Keys are strings or symbols that serve as property names, and values can be of any data type.&lt;br&gt;
&lt;/p&gt;

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

** Obiect Keys Method
const objKeys = { a: 1, b: 2, c: 3 };
console.log(Object.keys(objKeys)); // Output : ['a', 'b', 'c']

** Object Values Method
const objValues = { a: 1, b: 2, c: 3 };
console.log(Object.values(objValues)); // Output: [1,2,3]

** Object Entries Method
const objEntries = { a: 1, b: 2, c: 3 };
console.log(Object.entries(objEntries)); // Output [['a', 1],['b', 2],['c', 3]

** Object Assign Method
const target = { a: 1, b: 2 };
const source = { b: 3, c: 4 };
const result = Object.assign(target, source);
console.log(result); //  Output : {a: 1, b: 3,c: 4}

** Object freeze Method
const obj = { a: 1, b: 2 };
Object.freeze(obj);
obj.a = 3;
console.log(obj); // Output : {a: 1, b: 2}

** Object Seal Method
const obj = { a: 1, b: 2 };
Object.seal(obj);
obj.c = 3;
console.log(obj); // Output: {a: 1, b:2}

** Object hasOwnProperty Method
const obj = { a: 1 };
console.log(obj.hasOwnProperty("a")); // Output: true
console.log(obj.hasOwnProperty("toString")); // Output: false

** Object to Json String
const person = {
  name: "John",
  age: 30,
  city: "New York",
};
const jsonStr = JSON.stringify(person);
console.log(jsonStr); // Output: {"name":"John","age":30,"city":"New York"}

** JSON to Object
const jsonStr = '{"name":"John","age":30,"city":"New York"}';
const person = JSON.parse(jsonStr);

console.log(person.name); // Output: John
console.log(person.age); // Output: 30
console.log(person.city); // Output: New York
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Asynchronous operations in JavaScript using Promises&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Asynchronous operations for handling tasks that involve network requests, file operations, or time-consuming operations and ensure efficient non-blocking code execution.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// Promise 
** Asynchronous operations in JavaScript using Promises
function fetchData() {
  return new Promise((resolve, reject) =&amp;gt; {
    setTimeout(() =&amp;gt; {
      const data = { name: "John", age: 30 };
      if (data) {
        resolve(data);
      } else {
        reject(new Error("Data not found"));
      }
    }, 2000);
  });
}
fetchData()
  .then((data) =&amp;gt; {
    console.log(data);
  })
  .catch((error) =&amp;gt; {
    console.error(error);
  });

** fetch data using Promise method
fetch("https:/api.example.com/data")
  .then((response) =&amp;gt; response.json())
  .then((data) =&amp;gt; {
    console.log(data);
  })
  .catch((error) =&amp;gt; {
    console.error(error);
  });

** fetch data with async/await method
async function fetchData() {
  try {
    const response = await console.log(data);
  } catch (error) {
    console.error(error);
  }
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Conclusion&lt;/strong&gt;&lt;br&gt;
Mastering these 5 important things will provide a solid foundation for JavaScript development. You should learn these important things in JavaScript before going jump to frameworks and libraries of JavaScript.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>programming</category>
      <category>webdev</category>
      <category>react</category>
    </item>
  </channel>
</rss>
