<?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: waqas</title>
    <description>The latest articles on DEV Community by waqas (@waqasongithub).</description>
    <link>https://dev.to/waqasongithub</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%2F971313%2F3feac1d4-ff75-4671-a6e9-bfd8fb2c2aab.png</url>
      <title>DEV Community: waqas</title>
      <link>https://dev.to/waqasongithub</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/waqasongithub"/>
    <language>en</language>
    <item>
      <title>Day 02: Implementing JWT Authentication in NestJS with Passport (Part 1)</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Tue, 31 Dec 2024 12:09:13 +0000</pubDate>
      <link>https://dev.to/waqasongithub/day-02-how-to-implement-authentication-with-nest-js-and-passports-jwt-strategypart01-223k</link>
      <guid>https://dev.to/waqasongithub/day-02-how-to-implement-authentication-with-nest-js-and-passports-jwt-strategypart01-223k</guid>
      <description>&lt;h2&gt;
  
  
  First steps
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;nest g resource auth&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;This will further ask you for a selection &lt;br&gt;
&lt;code&gt;❯ REST API &lt;br&gt;
  GraphQL (code first) &lt;br&gt;
  GraphQL (schema first) &lt;br&gt;
  Microservice (non-HTTP) &lt;br&gt;
  WebSockets&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;select REST API and this will generate the whole module for you with the dtos services controller and module &lt;/p&gt;
&lt;h2&gt;
  
  
  Register User
&lt;/h2&gt;

&lt;p&gt;since we are implementing email/password-based authentication as the first step we will register the user.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Validate first to make sure the data is legitimate and add password strength validation to mitigate brute force attacks.&lt;/li&gt;
&lt;li&gt;Sanitize afterward to ensure the data is safe to use.&lt;/li&gt;
&lt;li&gt;Check that the user record already exists in the database if exists it means the user already has an account so send a response that's this email already registered.&lt;/li&gt;
&lt;li&gt;if the above checks failed it means we need to register a user 
take the user password and hash it with a good hashing library like bcrypt or argon2&lt;/li&gt;
&lt;li&gt;after hashing insert user record in DB. &lt;/li&gt;
&lt;li&gt;send an email to the user to verify is email legitimate.&lt;/li&gt;
&lt;li&gt;add rate-limiting to route to avoid DDoS attacks&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  1 Validate incoming data
&lt;/h2&gt;

&lt;p&gt;Since nest js has strong integration with recommended validation packages like class validator but from my previous experience I use zod for validation lot in react js front ends and so I found an awesome &lt;br&gt;
solution for nest js ecosystem called nests zod so I'll prefer to go with this one for now. To get started first install the library&lt;br&gt;
&lt;code&gt;npm i nestjs-zod&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createZodDto } from 'nestjs-zod';
import { z } from 'zod';
const passwordStrengthRegex =
  /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&amp;amp;])[A-Za-z\d@$!%*?&amp;amp;]{8,}$/;
const registerUserSchema = z
  .object({
    email: z.string().email(),
    password: z
      .string()
      .min(8)
      .regex(
        passwordStrengthRegex,
        'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character',
      ),
    confirmPassword: z.string().min(8),
  })
  .refine((data) =&amp;gt; data.password === data.confirmPassword, {
    message: 'Passwords do not match',
  });

export class RegisterUserDto extends createZodDto(registerUserSchema) {}

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

&lt;/div&gt;



&lt;p&gt;and then apply validation pipe on the route&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Post, Body, Version, UsePipes } from '@nestjs/common';
import { AuthService } from './auth.service';
import { RegisterUserDto } from './dto/register.dto';
import { ZodValidationPipe } from 'nestjs-zod';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}

  @Version('1')
  @Post()
  @UsePipes(ZodValidationPipe)
  async registerUser(@Body() registerUserDto: RegisterUserDto) {
    return await this.authService.registerUser(registerUserDto);
  }
}

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

&lt;/div&gt;



&lt;p&gt;if we provide all inputs correct&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5o25uk8bcf7tcueqfd4v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5o25uk8bcf7tcueqfd4v.png" alt="Image description" width="684" height="494"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so we are done with the first step &lt;/p&gt;

&lt;h2&gt;
  
  
  Let's Sanitize Data
&lt;/h2&gt;

&lt;p&gt;we have three inputs &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;password: typically passwords should not be Sanitize because they are never gonna sent and displayed to frontend even if someone sends a malicious script to the password  eventually it'll be hashed do not need &lt;/li&gt;
&lt;li&gt;confirmPassword: same story as above one &lt;/li&gt;
&lt;li&gt;email: yes emails are sent and rendered to clients so the email field must be Sanitize to mitigate injections and scripting attacks &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;but we explicitly added  email: z.string().email() which is enough for this use case &lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feyo9upvnv6i9jfcwx5yx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feyo9upvnv6i9jfcwx5yx.png" alt="Image description" width="800" height="673"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;but to add an extra lyre of security we can add a sanitization layer&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { createZodDto } from 'nestjs-zod';
import { z } from 'zod';
import * as xss from 'xss'; 

const passwordStrengthRegex =
  /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&amp;amp;])[A-Za-z\d@$!%*?&amp;amp;]{8,}$/;

const registerUserSchema = z
  .object({
    email: z.string().transform((input) =&amp;gt; xss.filterXSS(input)), // Sanitizing input using xss
    password: z
      .string()
      .min(8)
      .regex(
        passwordStrengthRegex,
        'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character',
      ),
    confirmPassword: z.string().min(8),
  })
  .refine((data) =&amp;gt; data.password === data.confirmPassword, {
    message: 'Passwords do not match',
  });

export class RegisterUserDto extends createZodDto(registerUserSchema) {}

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

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqn46hgxpwpzvft1ylbj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feqn46hgxpwpzvft1ylbj.png" alt="Image description" width="800" height="673"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This was a test we also added again back &lt;/p&gt;

&lt;p&gt;&lt;code&gt;email: z&lt;br&gt;
      .string()&lt;br&gt;
      .email()&lt;/code&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Step3,4,5
&lt;/h2&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import {
  BadRequestException,
  Injectable,
  InternalServerErrorException,
} from '@nestjs/common';
import { RegisterUserDto } from './dto/register.dto';
import { PrismaService } from 'src/prismaModule/prisma.service';
import * as argon2 from 'argon2';

@Injectable()
export class AuthService {
  constructor(private readonly prismaService: PrismaService) {}
  async registerUser(registerUserDto: RegisterUserDto) {
    // data is validate and sanitized by the registerUserDto
    const { email, password } = registerUserDto;

    try {
      // check if user already exists
      const user = await this.prismaService.user.findFirst({
        where: {
          email,
        },
      });

      if (user) {
        throw new BadRequestException('user already eists ');
      }
      //if use not exists lets hash user password
      const hashedPassword = await argon2.hash(registerUserDto.password);

      // time to create user
      const userData = await this.prismaService.user.create({
        data: {
          email,
          password: hashedPassword,
        },
      });

      if (!userData) {
        throw new InternalServerErrorException(
          'some thing went wrong while registring user',
        );
      }

      // if user is created successfully then  send email to user for email varification
      return {
        success: true,
        message: 'user created successfully',
      };
    } catch (error) {
      throw error;
    }
  }
}

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

&lt;/div&gt;


&lt;p&gt;The main point to notice I just returned a success message with no data related &lt;br&gt;
to the user like ID or email because it does not need to send back data to the user in this step. after registration user will be redirected to the login page to fill in details so avoiding sending unnecessary data is a good security practice &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghpbqcs552lc50sk8vyk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fghpbqcs552lc50sk8vyk.png" alt="Image description" width="800" height="673"&gt;&lt;/a&gt;  &lt;/p&gt;
&lt;h2&gt;
  
  
  Rate limiting
&lt;/h2&gt;

&lt;p&gt;implementing rate limiting in nestjs is very easy just install nestjs/throttler configure it globally and you're done .&lt;br&gt;
to install package run &lt;code&gt;npm i --save @nestjs/throttler&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
@Module({
  imports: [
    ThrottlerModule.forRoot([{
      ttl: 60000,
      limit: 10,
    }]),
  ],
})
export class AppModule {}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;then add nestjs throttle guard as global guard&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; providers: [
    AppService,

    {
      provide: APP_GUARD,
      useClass: ThrottlerGuard,
    },
  ],
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and here it is&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Controller, Post, Body, Version, UsePipes, Req } from '@nestjs/common';
import { AuthService } from './auth.service';
import { RegisterUserDto } from './dto/register.dto';
import { ZodValidationPipe } from 'nestjs-zod';
import { Throttle } from '@nestjs/throttler';

@Controller('auth')
export class AuthController {
  constructor(private readonly authService: AuthService) {}
  @Throttle({
    default: {
      ttl: 100000, // 1 minute
      limit: 5, // 5 requests per minute
    },
  })
  @Version('1')
  @Post()
  @UsePipes(ZodValidationPipe)
  async registerUser(@Body() registerUserDto: RegisterUserDto, @Req() req) {
    return await this.authService.registerUser(registerUserDto, req);
  }
}

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

&lt;/div&gt;



&lt;p&gt;since registering the user endpoint is a sensitive endpoint brute-force&lt;br&gt;
or dictionary attack can happen we kept the rate limit strict  &lt;/p&gt;

&lt;h2&gt;
  
  
  Send Verification Email
&lt;/h2&gt;

&lt;p&gt;for sending a verification email to a user's use Resend is an awesome easy-to-use service. but I decided to create a separate episode for the whole notification service so that understanding it becomes easier for everyone &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>nestjs</category>
      <category>fullstack</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Day 01 Designing Database Schema</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Mon, 30 Dec 2024 11:50:09 +0000</pubDate>
      <link>https://dev.to/waqasongithub/day-01-designing-database-schema-25pl</link>
      <guid>https://dev.to/waqasongithub/day-01-designing-database-schema-25pl</guid>
      <description>&lt;h2&gt;
  
  
  Lets Design Database Schema For First User Story
&lt;/h2&gt;

&lt;p&gt;As we know from from first episode we have these functional requirements&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;The user should be able to create an account.&lt;/li&gt;
&lt;li&gt;The user must have the ability to add prayers only during the designated prayer times.&lt;/li&gt;
&lt;li&gt;Prayer timings must be aligned with the user's time zone, considering the different prayer times in various cities and countries&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So the above requirement demonstrates we need to register the user to our system and the user should be able to mark prayers done or if he missed it will be marked missed. To meet requirements we need a user entity and prayer entity but for more granular control and to avoid redundancy, we also need a profile table. note I skipped analytics to&lt;br&gt;
make starting more easier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20p7k17kxwctaqz11xb4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F20p7k17kxwctaqz11xb4.png" alt="database erd" width="800" height="541"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Bit Explanation
&lt;/h2&gt;

&lt;p&gt;I added support of credentials and Google Oauth support in the user table for now I'll add just credentials authentication but later in the next phases, I'll add signIn with Google support. In the profile table which has a one-to-one relation with the user table, I added the user's social information.in the prayer table, I added all necessary fields to track and store user prayer information.&lt;/p&gt;

&lt;h2&gt;
  
  
  What's Next
&lt;/h2&gt;

&lt;p&gt;In the next episode, we'll implement complete credentials based   authentication with a stateless JWT auth mechanism with &lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>development</category>
      <category>api</category>
    </item>
    <item>
      <title>Building a Prayer Tracker: My 100 Days of Code Journey</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Mon, 30 Dec 2024 10:14:42 +0000</pubDate>
      <link>https://dev.to/waqasongithub/building-a-prayer-tracker-my-100-days-of-code-journey-mmh</link>
      <guid>https://dev.to/waqasongithub/building-a-prayer-tracker-my-100-days-of-code-journey-mmh</guid>
      <description>&lt;h2&gt;
  
  
  Building a Prayer Tracker: My 100 Days of Code Journey
&lt;/h2&gt;

&lt;p&gt;Building a project while learning to code alone can be boring, and creating clones by watching YouTube tutorials didn’t help much. I tried a few times but didn’t learn a lot.&lt;/p&gt;

&lt;h2&gt;
  
  
  So what I decided
&lt;/h2&gt;

&lt;p&gt;I decided to solve a real-world problem, starting with my own. &lt;/p&gt;

&lt;h2&gt;
  
  
  Motivation
&lt;/h2&gt;

&lt;p&gt;I’m not very religious, and I find it challenging to pray five times a day consistently. I’ve tried several prayer-tracking apps, but most feel too basic they only offer a simple checklist to mark whether I’ve prayed. I want something more personalized, with gamified challenges, progress tracking, and a sense of community to keep me motivated and engaged&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements Gathering
&lt;/h2&gt;

&lt;p&gt;Since I’m the originator of this idea, I started by creating a detailed requirements list. I divided the project into three phases to streamline development and follow an agile mindset. Each phase is further broken down into sprints, ensuring a structured and manageable approach to building the application.&lt;br&gt;
 ## Phase 1 &lt;/p&gt;

&lt;h2&gt;
  
  
  User Stories
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;As a user, I can mark my prayers as completed or missed.&lt;/li&gt;
&lt;li&gt;As a user, I can see the history of my previous days.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Although these requirements may seem simple at first glance, their implementation involves more complexity than it appears. To address this, I’ve outlined detailed functional requirements to ensure clarity and proper execution.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The user should be able to create an account.&lt;/li&gt;
&lt;li&gt;&lt;p&gt;The user must have the ability to add prayers only during the designated prayer times.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Prayer timings must be aligned with the user's time zone, considering the different prayer times in various cities and countries.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;There should be a feature to display user analytics on a calendar, allowing them to track progress and make improvements.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tech Stack
&lt;/h2&gt;

&lt;p&gt;Since I'm a JavaScript/TypeScript developer, for building APIs, I chose Nest.js. But why Nest.js and not Express.js? As a learner, using opinionated frameworks provides many benefits, such as project architecture, and industry-standard design patterns for implementing features, and it's easier to maintain the codebase and write clean, modular code. The list goes on and on. For the web front end, I chose React.js, and for the mobile app, I'll go with React Native.&lt;/p&gt;

&lt;h2&gt;
  
  
  Final Words
&lt;/h2&gt;

&lt;p&gt;As I mentioned earlier, I am learning to code, so any suggestions, constructive feedback, or corrections will be highly appreciated. The main motive of writing here is to add a sense of accountability and to build in public, which will only be accomplished with your help. Thanks in advance for assisting me on my journey.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>All You Need To Know About Arrays In JavaScript (1)</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Mon, 19 Dec 2022 22:51:48 +0000</pubDate>
      <link>https://dev.to/waqasongithub/all-you-need-to-know-about-arrays-in-javascript-1-4ikc</link>
      <guid>https://dev.to/waqasongithub/all-you-need-to-know-about-arrays-in-javascript-1-4ikc</guid>
      <description>&lt;p&gt;&lt;strong&gt;Let's Try To  Know Why We Need Arrays In Programming.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;let's try this scenario we need to write a straightforward program average to five numbers.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let  a=1 ,b=2 ,c=3 ,d=4 ,e=5;
let avarage= (a+b+c+d+e) /5
console.log(avarage) // 3
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Problems we can figure out&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;No efficient way to store data &lt;/li&gt;
&lt;li&gt;it's so time-consuming &lt;/li&gt;
&lt;li&gt;we can not access data in a super easy way &lt;/li&gt;
&lt;li&gt;if we use only variables it will be so hard to 
debug and figure out things.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Soulution&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Array
&lt;/h2&gt;

&lt;p&gt;Array Syntex&lt;br&gt;
let arrayname= [elemet1 .elemet2 ,elment3 ... ]&lt;/p&gt;

&lt;p&gt;characteristics of array data structure &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;we can store any data type in array like(number, string, boolean, NaN, undefined, other arrays, objects…).&lt;/li&gt;
&lt;li&gt;Data is stored in an array in a contiguous fashion that makes it easy to 
access data from the array
&lt;/li&gt;
&lt;/ol&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Let numbers = [1,2,3,4,5] 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;strong&gt;Second  less used  way To Create Array&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let arr = new array(1,2,3,4,5,6,7,8)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;*&lt;em&gt;Benefits *&lt;/em&gt;&lt;br&gt;
 Data is organized in contagious blocks which are easy to access and modify.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Operations On Arrays Data structure.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.How To Acess?&lt;/strong&gt;&lt;br&gt;
 &lt;strong&gt;2. how to modify&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foilzt55hm8eeh5ceaq2z.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Foilzt55hm8eeh5ceaq2z.png" alt="Image description" width="548" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So in the above image, we can look at each element of the array as stored at a specific index so we can Access that eleDelete element 3ment through the index.&lt;br&gt;
&lt;em&gt;syntex: arrayname[index]&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1 Acess&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(numbers[0]) // 1
console.log(numbers[3]) // 4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The first element in the array has an index of 0, the second element has an index of 1, and so on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2 modify&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Add Element&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers[3] ="mydogname"
console.log(numbers) // [1,2,3,'mydogname' 5]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;yes, we can store any data type in arrays also.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Delete element&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt; Delete numbers[3] 
console.log(numbers)  // [1,2,3, empty ,5] 

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

&lt;/div&gt;



&lt;p&gt;the very interesting thing to notice we try to delete the array element &lt;br&gt;
traditionally and we see "empty" at the undefined index.&lt;br&gt;&lt;br&gt;
 resulted array also called spare array.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fte93b0l0cokkcmjapyxu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fte93b0l0cokkcmjapyxu.png" alt="Image description" width="323" height="174"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;let's add again value at index 3.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;numbers[3]=4
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Array properties  necessary to know&lt;/strong&gt;&lt;br&gt;
Before we work on the array we need to know about the array property length&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;console.log(numbers.length)  // 5

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

&lt;/div&gt;



&lt;p&gt;what if we need to access all elements, not just a single element?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Iterating On Array&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;for (let i =0 ; i&amp;lt;numbers.length ; i++ ) {
    console.log(numbers[i])     //  1,2,3,4,5    
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;so what  it will work like that &lt;/p&gt;

&lt;p&gt;first iteration. value of i =0    numbers[0] --&amp;gt; element at index 0  second iteration. value of i =1    numbers[1] --&amp;gt; element at index1  third  iteration. value of i =0    numbers[2] --&amp;gt; element at index2 fourth iteration. value of i =0    numbers[3] --&amp;gt; element at index3 fifth iteration. value of i =0    numbers[4] --&amp;gt; element at index 4 &lt;/p&gt;

&lt;p&gt;so I &amp;lt;numbers. length condition is met loop will be stopped.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Now we are ready to get the average of numbers in an array in an efficient way. *&lt;/em&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let numbers = [1,2,3,4,5] 
let average=0;
let sum=0


for(let i=0 ;i&amp;lt;numbers.length ;i++)
{
    console.log(numbers[i])
    sum=sum +numbers[i]

}

  average = sum/numbers.length
   console.log(average)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Benefits again to Remember&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;now we can add how my numbers as we want without repeating ourselves&lt;br&gt;&lt;br&gt;
which is the rule of programming DRY(DON'T REPEAT YOURSELF).&lt;/p&gt;

&lt;p&gt;so guys that's, for now, stay tuned for the second episode about array methods.  &lt;/p&gt;

</description>
      <category>mobile</category>
      <category>android</category>
      <category>ios</category>
    </item>
    <item>
      <title>Javascript Data Types in Depth(2)</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Sun, 11 Dec 2022 19:49:22 +0000</pubDate>
      <link>https://dev.to/waqasongithub/javascript-data-types-in-depth2-3i2l</link>
      <guid>https://dev.to/waqasongithub/javascript-data-types-in-depth2-3i2l</guid>
      <description>&lt;p&gt;In JavaScript, there are only two main non-primitive data types: objects and arrays. These data types are considered non-primitive because they are complex data structures that can be used to store and organize many different types of data.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Arrays&lt;/strong&gt;&lt;br&gt;
&lt;strong&gt;2.objects&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Lets Learn prerequisites first&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Heap&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;In computer science, the heap is a region of memory that is used to store objects and other complex data structures. It is a dynamic data structure, which means that it can grow and shrink in size as needed to accommodate the data being stored in it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Stack&lt;/strong&gt;&lt;br&gt;
In computer science, the stack is a region of memory that is used to store primitive data types and the memory addresses of data structures on the heap. It is a Last In First Out (LIFO) data structure, which means that the last item added to the stack is the first item that can be removed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So How Non Primitive(reference) Data Type Work&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you create a new object or array in JavaScript, the data structure is stored on the heap and a reference to it is stored on the stack. This means that when you access the object or array, you are actually accessing the reference on the stack, which points to the data on the heap.&lt;/p&gt;

&lt;p&gt;`let arr =[1,2,3,4,5]&lt;/p&gt;

&lt;p&gt;// The "arr" array  is stored on the heap&lt;br&gt;
  // A reference to the "arr" array  is stored on the stack&lt;/p&gt;

&lt;p&gt;let person = {&lt;br&gt;
    name: "John Doe",&lt;br&gt;
    age: 35&lt;br&gt;
  };&lt;/p&gt;

&lt;p&gt;// The "person" object is stored on the heap&lt;br&gt;
  // A reference to the "person" object is stored on the stack&lt;br&gt;
  `&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;But What Happen When We Mutate Array or Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When you mutate an array or object in JavaScript, the data on the heap is updated to reflect the changes, but the reference on the stack remains the same. This means that when you access the array or object after mutating it, you are still using the same reference on the stack to find the updated data on the heap.&lt;br&gt;
`&lt;br&gt;
// Create a new array&lt;br&gt;
let numbers = [1, 2, 3];&lt;/p&gt;

&lt;p&gt;// The "numbers" array is stored on the heap&lt;br&gt;
// A reference to the "numbers" array is stored on the stack&lt;/p&gt;

&lt;p&gt;// Mutate the array&lt;br&gt;
numbers.push(4);&lt;/p&gt;

&lt;p&gt;// The data on the heap is updated to [1, 2, 3, 4]&lt;br&gt;
// The reference on the stack remains the same&lt;/p&gt;

&lt;p&gt;// Access the array&lt;br&gt;
let lastNumber = numbers[3];&lt;/p&gt;

&lt;p&gt;// The reference on the stack is used to find the updated data on the heap`&lt;/p&gt;

&lt;p&gt;codepen link &lt;br&gt;
"&lt;a href="https://codepen.io/waqas-on-github/pen/vYrwNaz?editors=0012"&gt;https://codepen.io/waqas-on-github/pen/vYrwNaz?editors=0012&lt;/a&gt;"&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>beginners</category>
      <category>tutorial</category>
    </item>
    <item>
      <title>Javascript Data Types in Depth(1)</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Sun, 11 Dec 2022 18:53:57 +0000</pubDate>
      <link>https://dev.to/waqasongithub/javascript-data-types-in-depth1-2ba8</link>
      <guid>https://dev.to/waqasongithub/javascript-data-types-in-depth1-2ba8</guid>
      <description>&lt;p&gt;&lt;strong&gt;what are  data types&lt;/strong&gt; &lt;br&gt;
in computer programming, a data type is a classification of types of data that determines the possible values and operations that can be performed on that data. Data types are an essential concept in any programming language, as they provide a way for programmers to represent and manipulate data in a structured and organized manner.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Data types in JavaScript **&lt;br&gt;
**Primitive and reference (non primitive)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Numbers&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;let num =100;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2.strings&lt;/strong&gt;&lt;br&gt;
let str=&lt;code&gt;hello world&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. boolean&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;let present =True&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Undefined&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;let myundefined = undefined&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;5.Null&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;let mynull=Null&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When a variable with a primitive data type is created, the value of that data type is directly stored in the memory allocated for the variable.&lt;br&gt;
 For example, if you have a string variable called 'myString' with the value "Hello", the string value "Hello" is directly stored in the memory allocated for the 'myString' variable. This means that the amount of memory required to store a primitive value is equal to the size of the value itself.&lt;/p&gt;

&lt;p&gt;However, this does not mean that you can change the value of the string directly. As I mentioned earlier, primitive data types in JavaScript are immutable, which means they cannot be changed once they have been created. This means that if you want to change the value of a string, you have to create a new string with the new value, and then assign that new string to the same variable.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;var myString = "Hello"; // Create a string variable with the value "Hello"&lt;br&gt;
myString = "Goodbye";   // Create a new string with the value "Goodbye" and assign it to the same variable&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;So, to summarize, it is possible to update the value of a variable with a primitive data type in JavaScript. However, this does not change the value of the primitive data type itself, which remains immutable. It is only reference data types that are mutable and can be directly modified. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Master Css Selectors The Easy Way (part 1)</title>
      <dc:creator>waqas</dc:creator>
      <pubDate>Sat, 12 Nov 2022 21:25:02 +0000</pubDate>
      <link>https://dev.to/waqasongithub/master-css-selectors-the-easy-way-part-1-12aa</link>
      <guid>https://dev.to/waqasongithub/master-css-selectors-the-easy-way-part-1-12aa</guid>
      <description>&lt;p&gt;so you are here to learn about css selectors. So question arise why we need selectors&lt;/p&gt;

&lt;p&gt;In CSS, selectors are used to target the HTML elements on our web pages that we want to style.&lt;/p&gt;

&lt;p&gt;so let me explain with code  examples.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_Scenario _&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5G7oAQQS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kj556oxk9zp0gc220zz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5G7oAQQS--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1kj556oxk9zp0gc220zz.png" alt="Image description" width="596" height="83"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we wanna change background color of "P" element the easiest way is to select an element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ECoD7yki--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tzo0l72nlx84qrrky5jt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ECoD7yki--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tzo0l72nlx84qrrky5jt.png" alt="Image description" width="560" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Result&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--FedrNFhU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q05eelrulwi8nyvsroz4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--FedrNFhU--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/q05eelrulwi8nyvsroz4.png" alt="Image description" width="560" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;we selected an element and change its background color but we can do all sophisticated stuff in this way?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_Introducing ID and class selectors _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;class selector&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;here's a solution to make our lives a little bit easier.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WTBc9PVC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vgi9y46vjrhohl9xzsuu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WTBc9PVC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vgi9y46vjrhohl9xzsuu.png" alt="Image description" width="819" height="279"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;our customer wanna order "Dumplings" so we will add class attribute  in second child of ul and change its background color green as ordered food.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--E-DMceJj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lu1on846cf1eyzlhykwu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--E-DMceJj--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lu1on846cf1eyzlhykwu.png" alt="Image description" width="880" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_result _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uLrLoDpp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjgh6s9fs4hqtvtkszyp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uLrLoDpp--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kjgh6s9fs4hqtvtkszyp.png" alt="Image description" width="390" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;oh no our customer changed mind and he want more food he want "Ma Po Tofu" also  fortunately class selector come to save us we have to just add "orders" class in that element also.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;NOTE&lt;/strong&gt; classes always targeted with "." in css &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2k3gm9-D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdezbmddeypt08wncvtq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2k3gm9-D--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gdezbmddeypt08wncvtq.png" alt="Image description" width="880" height="487"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;result&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--h2dBPnqg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eonl3bv5awjneoljc9yr.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--h2dBPnqg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/eonl3bv5awjneoljc9yr.png" alt="Image description" width="390" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so we get the idea of how classes work but what about "id's" and why?  id's here when classes can do everything let's talk about that.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_Id selector _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;id is simple just we can target one element with one id I mean id will be always unique we can't use it with multiple elements &lt;br&gt;
&lt;strong&gt;NOTE&lt;/strong&gt;  id's always targeted with "#" in css &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Wqsv7R_j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mcgk0ji6krr850n50i7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Wqsv7R_j--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9mcgk0ji6krr850n50i7.png" alt="Image description" width="636" height="263"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aUQPlK6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9md8of3hldj1h8vu6uk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aUQPlK6U--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/j9md8of3hldj1h8vu6uk.png" alt="Image description" width="635" height="128"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;result&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--GuN1KIvu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wa73z37x6a19x9gncgrs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--GuN1KIvu--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wa73z37x6a19x9gncgrs.png" alt="Image description" width="390" height="152"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;But if we want add same id to other element** we cant **&lt;br&gt;
but we can add same class to multiple elements so i think it'll make sense obviously .&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;So these are most basic selectors *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;BUT&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;_if you wanna become css guru bear me more _&lt;/p&gt;

&lt;p&gt;Next one &lt;br&gt;
*&lt;em&gt;_ chained selector_ *&lt;/em&gt;&lt;br&gt;
lets assume we have requirement to style a button but not one button 3 buttons  all buttons have similar styling but third one has bit different so let see how we can accomplish this with chained selectors &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--4SlmtFfC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tv537t4fkzxv931rk7o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--4SlmtFfC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3tv537t4fkzxv931rk7o.png" alt="Image description" width="880" height="243"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KhDJEZoh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv1sc5gu89v95yv87ukz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KhDJEZoh--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pv1sc5gu89v95yv87ukz.png" alt="Image description" width="609" height="173"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so in above example we can clearly see how chained selectors can help us in different situations.&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;&lt;em&gt;result&lt;/em&gt; *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zrgFpap3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pdwn2a3i0zkh8odlehe.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zrgFpap3--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4pdwn2a3i0zkh8odlehe.png" alt="Image description" width="414" height="94"&gt;&lt;/a&gt;&lt;br&gt;
let see another example to clear this concept more &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--PX5V6n3R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cpieo1snydogybxv0f6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--PX5V6n3R--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cpieo1snydogybxv0f6.png" alt="Image description" width="880" height="313"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;here our goal is to target li element which have " bg_black and text_white" classes&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_Css will be _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fXdSQVFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23k4md67hannaajj2t02.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fXdSQVFi--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/23k4md67hannaajj2t02.png" alt="Image description" width="880" height="183"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;&lt;em&gt;result&lt;/em&gt; *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_HIrGo3c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bo2tud587r3r13u77m81.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_HIrGo3c--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/bo2tud587r3r13u77m81.png" alt="Image description" width="414" height="106"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;in this snippet we are telling in whole page any 'li'  element which have "bg_black and text_white" classes change its background color and text color &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_Direct Child Selector _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HnjwoPzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dd5dut4xwznpi5yzy4ui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HnjwoPzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/dd5dut4xwznpi5yzy4ui.png" alt="Image description" width="880" height="376"&gt;&lt;/a&gt;&lt;br&gt;
in same snippet  with some changes we used above what if we want to target all  "li" element so we accomplish this via Direct Child Selector.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--WU5AAFql--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xd8cdcj3fw894rhiytx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--WU5AAFql--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xd8cdcj3fw894rhiytx2.png" alt="Image description" width="531" height="129"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;result&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--dpuximdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxk4k9rv7py821bmttyf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--dpuximdk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mxk4k9rv7py821bmttyf.png" alt="Image description" width="591" height="204"&gt;&lt;/a&gt;&lt;br&gt;
&lt;strong&gt;Note&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;3rd li which is not direct child is not selected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Adjacent Sibling Selector&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The + selector is used to select an element that is directly after another specific element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vrMK_Rgx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82hkj83onbr6hk4otejy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vrMK_Rgx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/82hkj83onbr6hk4otejy.png" alt="Image description" width="818" height="726"&gt;&lt;/a&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zbBEDllk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c98amtlkm1l7aovcx2rf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zbBEDllk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/c98amtlkm1l7aovcx2rf.png" alt="Image description" width="762" height="159"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;&lt;em&gt;result&lt;/em&gt; *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--uGttZ5wP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pth541aj3jzpwym4i3xl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--uGttZ5wP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pth541aj3jzpwym4i3xl.png" alt="Image description" width="390" height="297"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Hover selector&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
hover is relay simple selector when we mouse over on any element it'll apply CSS which we want &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5TOVYN6V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09csrg12s2zywmsg1kdl.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5TOVYN6V--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/09csrg12s2zywmsg1kdl.png" alt="Image description" width="880" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_result _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DqObNUsx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv42topnioa7ehrnu6uj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DqObNUsx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uv42topnioa7ehrnu6uj.png" alt="Image description" width="174" height="109"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Before Selector&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;before selector  is pseudo selector which inserts something before the content of each selected element.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--iFtt8sCk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vx5ijmwldtmdmffa61b3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--iFtt8sCk--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vx5ijmwldtmdmffa61b3.png" alt="Image description" width="880" height="653"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_result _&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tvx_kMcG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y64lbmtp6zcs7pdgepem.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tvx_kMcG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y64lbmtp6zcs7pdgepem.png" alt="Image description" width="251" height="193"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_After selector _&lt;/strong&gt;&lt;br&gt;
After selector is completely opposite of before selector so its relay simple &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Q1aMq4ER--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9klo691brrno74vflu0j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Q1aMq4ER--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9klo691brrno74vflu0j.png" alt="Image description" width="780" height="667"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;_ result _&lt;/strong&gt; &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--aQE1Hws---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxv2675h1581t8l7xp7m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--aQE1Hws---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lxv2675h1581t8l7xp7m.png" alt="Image description" width="180" height="187"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;so we can clear see result now button is before blue box.&lt;/p&gt;

&lt;p&gt;So today we learn few css selectors if you want to learn more in this beginner friendly way stay connected Thanks.   &lt;/p&gt;

</description>
      <category>css</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>ux</category>
    </item>
  </channel>
</rss>
