<?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: BHAVANA S</title>
    <description>The latest articles on DEV Community by BHAVANA S (@bhavanasjpg).</description>
    <link>https://dev.to/bhavanasjpg</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%2F531969%2Fbe45314e-8988-4e53-a820-af64b6815fa4.jpg</url>
      <title>DEV Community: BHAVANA S</title>
      <link>https://dev.to/bhavanasjpg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/bhavanasjpg"/>
    <language>en</language>
    <item>
      <title>Understanding call(),apply(),bind() in Javascript</title>
      <dc:creator>BHAVANA S</dc:creator>
      <pubDate>Wed, 28 Sep 2022 08:21:20 +0000</pubDate>
      <link>https://dev.to/bhavanasjpg/understanding-callapplybind-in-javascript-1kl2</link>
      <guid>https://dev.to/bhavanasjpg/understanding-callapplybind-in-javascript-1kl2</guid>
      <description>&lt;h2&gt;
  
  
  Topics covered
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Why we need call(),apply(),bind()?&lt;/li&gt;
&lt;li&gt;What is call(),apply(),bind()?&lt;/li&gt;
&lt;li&gt;When to use call(),apply(),bind()?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Traditionally in javascript, you can have objects that have their own properties and methods, one object cannot use the methods of another object but there is a way to overcome this restriction.&lt;br&gt;
By using call(), apply() and bind() methods to tie a function into an object and call that function as if it belonged to that object.&lt;/p&gt;

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

&lt;p&gt;We know that functions are a special kind of objects in JavaScript. So they have access to some methods and properties. To prove functions are objects, we can do something like this, for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function printMessage() {
  console.log('Welcome!');
}
printMessage.city = 'Bangalore';

// Prints 'Bangalore'
console.log(printMessage.city);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;JavaScript also provides some special methods and properties to every function object. So every function in JavaScript inherits those methods. Call, bind, and apply are some of the methods that every function inherits.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;call() :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;By using call() you can tie a function into an object, this way you can call the function as if it belonged to the object.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = {
  number: 2
}

function add(a,b){
  return this.number + a + b;
}
console.log(add.call(object,3,5));// prints 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;apply() :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The apply() method does the exact same as call().&lt;br&gt;
The difference is that call() accepts an argument list, but apply() accepts an array an array of arguments.&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = {
  number: 2
}

function add(a,b){
  return this.number + a + b;
}
console.log(add.apply(object,[3,5]));// prints 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can use apply() to append an array to another array, for 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 numbers = [1,2,3];
const moreNumbers = [4,5,6];
numbers.push.apply(numbers, moreNumbers);
console.log(numbers); // prints [1,2,3,4,5,6]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;bind() :&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The bind() method is reminiscent of call() and apply(), but instead of executing a function immediately , bind() returns a function that can be executed later on.&lt;br&gt;
Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let object = {
  number: 2
}

function add(a,b){
  return this.number + a + b;
}

const func = add.bind(object,3,5);
console.log(func())
// prints 10
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Function currying using bind():&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let multiply = function(x,y){
  console.log(x * y); //prints 10
}
let multiplyByTwo = multiply.bind(this, 2);
multiplyByTwo(5);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here in this example, we created multiply function which multiplies two parameters x and y and logs it to the console.&lt;/p&gt;

&lt;p&gt;Now let us create another function multiplyByTwo which is exactly the copy of multiply. We will generally create this copy by executing the bind method over multiply. Over here we will pass generally passing some arguments. The second argument we will pass is 2.&lt;/p&gt;

&lt;p&gt;As we know that when we call the bind method gives the copy of the multiply method and doesn’t invoke it directly. So this means that the value 2 will be set as the value of x. So now let us execute the multiplyByTwo function.&lt;/p&gt;

&lt;p&gt;Thanks for reading, happy to hear feedback and suggestion in comments section.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webdev</category>
      <category>beginners</category>
      <category>programming</category>
    </item>
    <item>
      <title>All you know about media queries</title>
      <dc:creator>BHAVANA S</dc:creator>
      <pubDate>Tue, 15 Dec 2020 17:02:17 +0000</pubDate>
      <link>https://dev.to/bhavanasjpg/all-you-know-about-media-queries-7o8</link>
      <guid>https://dev.to/bhavanasjpg/all-you-know-about-media-queries-7o8</guid>
      <description>&lt;p&gt;While building a website, sometimes we got many confusions about how to make it responsive? what is that responsive mean? what is that media query? why we need that and how to use that?&lt;/p&gt;

&lt;p&gt;Cool, you will get an answers for the above questions here, let's go with  responsive first&lt;/p&gt;

&lt;p&gt;A responsive website will display a different interface depending on what device is used to access the site.&lt;/p&gt;

&lt;p&gt;For example, the font-size of text, images width and height, padding, margin, and many other CSS properties will have different values for different screen sizes, like a website may appear one way on a laptop, another way on a tablet, and still another way on a smartphone.&lt;/p&gt;

&lt;p&gt;That's what responsive mean, then how to make our website responsive, there are several ways for that,&lt;/p&gt;

&lt;p&gt;One method is to dynamically detect the user's platform and load specific HTML and CSS for the corresponding device.&lt;/p&gt;

&lt;p&gt;Another option is to use media queries, which automatically loads different CSS styles depending on the size of the browser window.&lt;/p&gt;

&lt;p&gt;Then what is the media query? Wait, here we go,&lt;/p&gt;

&lt;p&gt;Media query is a feature of CSS, which acts as filters for different screen sizes means it enable the webpage content to adapt to different screen sizes and resolutions.&lt;/p&gt;

&lt;p&gt;why we need media queries? because to customize the appearance of websites for multiple devices.&lt;/p&gt;

&lt;p&gt;How to use media queries? &lt;/p&gt;

&lt;p&gt;Media queries may be inserted within a webpage's HTML or included in a separate .css file referenced by a webpage.&lt;/p&gt;

&lt;p&gt;Ex:&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--8cyTfajG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gmf524n05n7fupdc6nh2.PNG" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--8cyTfajG--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/gmf524n05n7fupdc6nh2.PNG" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The media query above activates if a user's browser window is 768 pixels wide or less. This could happen if you shrink your window on a desktop computer or if you are using a mobile device such as a tablet, to view the webpage.&lt;/p&gt;

&lt;p&gt;You can also write media queries for different media types like:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Ex: @media print and(max-width:360px){ }&lt;br&gt;
print define intended for paged material and documents viewed &lt;br&gt;
 on a screen in print preview mode.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ex: @media screen and(min-width:670px){ }&lt;br&gt;
Intended primarily for screens.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ex :@media speech and(max-width:1024px){ }&lt;br&gt;
Intended for speech synthesizers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Ex: @media all and (min-width:520px){  }   all define suitable &lt;br&gt;
 for all devices.                                 &lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;And at last, like all modules within a cascading stylesheet, the ones that appear further down the list override the ones above them. Therefore the default styles are typically defined first within a CSS document, followed by the media queries for different screen sizes.&lt;/p&gt;

&lt;p&gt;For example, the desktop style might be defined first, followed by a media query will styles for tablet users, followed by a media query designed for smartphone users and styles may also be defined in opposite order. &lt;/p&gt;

&lt;p&gt;Thanks for reading ,it's my first blog ,happy to hear a feedback and suggestion in comments section                                     &lt;/p&gt;

</description>
      <category>css</category>
      <category>mediaquery</category>
      <category>responsivewebdesign</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
