<?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: Hozan</title>
    <description>The latest articles on DEV Community by Hozan (@hozan).</description>
    <link>https://dev.to/hozan</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%2F615327%2F9c45b79b-5481-4bf9-8953-b7f88c250ba7.png</url>
      <title>DEV Community: Hozan</title>
      <link>https://dev.to/hozan</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/hozan"/>
    <language>en</language>
    <item>
      <title>Creating Objects in JavaScript.</title>
      <dc:creator>Hozan</dc:creator>
      <pubDate>Sat, 01 May 2021 18:34:55 +0000</pubDate>
      <link>https://dev.to/hozan/creating-objects-in-javascript-hd3</link>
      <guid>https://dev.to/hozan/creating-objects-in-javascript-hd3</guid>
      <description>&lt;p&gt;Last week I covered primitives values and objects and their differences, this week I will touch upon the topic of how to create objects using different syntaxes and summarise them here, so you can have a rough idea of how they can be created and the benefit of each syntax.&lt;/p&gt;

&lt;p&gt;If you are beginner (like me) there is a high a chance that so far when you created objects you used the &lt;strong&gt;literal notation&lt;/strong&gt; (also called Object Initializer), below is an example of an object created with literal notation:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myCar = {
    carMake: 'Ford',
    carModel: 'Mustang',
    carYear: 1969
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but in JavaScript there is another way to create objects, using the &lt;strong&gt;constructor function&lt;/strong&gt;. Below is an example of the same object as above created using the constructor functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Car(make, model, year) {
  this.carMake = make;
  this.carModel = model;
  this.carYear = year;
}
var myCar = new Car('Ford', 'Mustang', 1969);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To achieve that we have to do the following steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Define the object type, in our case here the type is &lt;code&gt;Car&lt;/code&gt;, and we defined it using a constructor function. Also note that there is a strong convention to name constructor functions with an upper-case first letter, hence we used &lt;code&gt;Car&lt;/code&gt; and not &lt;code&gt;car&lt;/code&gt;.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Add &lt;code&gt;this&lt;/code&gt; keyword to every property, when doing so it will assign values to the object's properties based on the values passed to the function.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Create an instance of the object with &lt;code&gt;new&lt;/code&gt; operator.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can see the advantage of using a constructor functions (with the help of &lt;code&gt;new&lt;/code&gt;) is that you can create multiple and even hundreds new instances of the object type. Therefore, you can have multiple different objects with same properties and methods as shown below :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var car1 = new Car('Nissan', '300ZX', 1992);
var car2 = new Car('Mazda', 'Miata', 1990);
etc..
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, when it comes to simple objects it is best to stick with literal notation as it is faster to run and easier to read since we do not need to instantiate it first like we do with constructor functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// constructor function:
var myCar = new Car('Ford', 'Mustang', 1969);
console.log(myCar.carMake)    //’Ford’

// literal notation
console.log(myCar.carMake)    //’Ford’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These two syntaxes also have their difference when adding new methods or new properties.&lt;/p&gt;

&lt;h4&gt;
  
  
  To add a property or a method to a predefined object created with literal notation consider the following object:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myCar = {
    carMake: 'Ford',
    carModel: 'Mustang',
    carYear: 1969
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Adding a property:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;consider we want to add property &lt;code&gt;color&lt;/code&gt; with a value equal to “black”, to achieve that we do the following east step:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;myCar.carColor = “black”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Now we have the object modified and it will look like below :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myCar = {
    carMake: 'Ford',
    carModel: 'Mustang',
    carYear: 1969;
    carColor: ‘black’
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Adding a method: &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To do that, we define a property name (or key) with its value being a function definition:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myCar.carDetalis = function (){
      return this.carMake + “ “ + this.carModel;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note that we used &lt;code&gt;this&lt;/code&gt; keyword when defining a method, it refers to the "owner" of the function. So in our case here the “owner” is &lt;code&gt;myCar&lt;/code&gt; object, the property name is &lt;code&gt;carDetails&lt;/code&gt; and the function definition is &lt;code&gt;function () { return this.carMake + “ “ + this.carModel; }&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log(myCar.carDetails());   // ‘Ford Mustang’&lt;/code&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  To achieve what we did in the above examples when an object is created using constructor functions consider this object:
&lt;/h4&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Car(make, model, year) {
  this.carMake = make;
  this.carModel = model;
  this.carYear = year;
}

var myCar = new Car('Ford', 'Mustang', 1969);
var car1 = new Car('Nissan', '300ZX', 1992);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Adding a property :&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you want to add a property to &lt;code&gt;myCar&lt;/code&gt; then it very simple, it is the same when adding a property to an object created with literal notation.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;myCar.carColor = “black” ;
console.log(myCar.carColor);  // ‘black’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However this property will only be added to &lt;code&gt;myCar&lt;/code&gt; object, and not any other objects created with the same construcuor function, so if you were to access such a property in &lt;code&gt;car1&lt;/code&gt; you will get undefined.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;console.log(car1.carColor)  // undefined&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;To add the new property to all objects created with the same constructor function , you have to add the property to the definition of the Car object type.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Car(make, model, year, color) {
  this.carMake = make;
  this.carModel = model;
  this.carYear = year;
  this.carColor = color;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, there is another way around this if we want to add the new property which is simpler and quicker, especially if our script is hundred of lines long, we use &lt;code&gt;Function.prototype.property&lt;/code&gt;  , and this is only available to object's created with the constructor syntax.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car.prototype.color = 'black';
console.log(car1.color);    // 'black'
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Adding a method:&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just like adding a property, it is also has similar approach. So you can either add the method to the constructor function itself or use &lt;code&gt;Function.prototype.property&lt;/code&gt; , which will have the method avialbe to all objects created with the same function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Car(make, model, year, color) {
  this.carMake = make;
  this.carModel = model;
  this.carYear = year;
  this.carColor = color;
  this.carDetails = function (){
      return this.carMake + “ “ + this.carModel;
}

console.log(myCar.carDetails()) // ‘Ford Mustang’
console.log(car1.carDetails()) // ‘Nissan 300ZX’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Car.prototype.carDetails = function (){
      return this.carMake + “ “ + this.carModel;
}

console.log(myCar.carDetails()) // ‘Ford Mustang’
console.log(car1.carDetails()) // ‘Nissan 300ZX’
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to know what the &lt;code&gt;new&lt;/code&gt; operator does behind the scenes  you can read this amazing &lt;a href="https://codeburst.io/javascript-for-beginners-the-new-operator-cee35beb669e"&gt;article&lt;/a&gt; which also explains why we need it to create objects when using constructor functions.&lt;/p&gt;

&lt;p&gt;If you have any suggestions or questions, leave them below.&lt;/p&gt;

&lt;p&gt;Happy coding :) .&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>objects</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Primitives values and JavaScript Objects</title>
      <dc:creator>Hozan</dc:creator>
      <pubDate>Sun, 25 Apr 2021 00:32:28 +0000</pubDate>
      <link>https://dev.to/hozan/primitives-values-and-javascript-objects-3c2n</link>
      <guid>https://dev.to/hozan/primitives-values-and-javascript-objects-3c2n</guid>
      <description>&lt;p&gt;“In JavaScript, objects are king. If you understand objects, you understand JavaScript.” (w3schools)&lt;/p&gt;

&lt;p&gt;All JavaScript values such as Arrays, Functions, Objects and Regular Expressions are considered to be objects, except primitives values, these are not objects.&lt;/p&gt;

&lt;p&gt;Primitives values are values that have no properties or methods, and the following is a list of what is called primitives data types ,which are a type of data that have primitives values :&lt;br&gt;
    • string&lt;br&gt;
    • number&lt;br&gt;
    • boolean&lt;br&gt;
    • null&lt;br&gt;
    • undefined&lt;/p&gt;

&lt;p&gt;So for example, if we have a string that says &lt;code&gt;“I am a string”&lt;/code&gt; , the primitive value in this case is  &lt;code&gt;“I am a string”&lt;/code&gt; and the primitive data type is string.&lt;/p&gt;

&lt;p&gt;But you might ask, if primitives values or primitives data types have no properties or methods, then how come the primitive value &lt;code&gt;“I am string”&lt;/code&gt; have property &lt;code&gt;length&lt;/code&gt; and other methods such as &lt;code&gt;charAt()&lt;/code&gt;. &lt;/p&gt;

&lt;p&gt;Well first we need to know what is a &lt;code&gt;String&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;A &lt;code&gt;String&lt;/code&gt; object, is a JavaScript built-in object, this &lt;code&gt;String&lt;/code&gt; object also have a property called &lt;code&gt;'prototype'&lt;/code&gt;, this property value itself acts as a template object that contains methods and properties we can use and can be inherited. &lt;br&gt;
Hence the reason we have methods such as &lt;code&gt;String.prototype.charAt()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In JavaScript and other programming languages, they have the ability to convert a value from one data type to another (e.g numbers to strings,  or a string to an object).&lt;/p&gt;

&lt;p&gt;This kind of a conversion is called coercion , and it is done automatically. And to achieve that all we have to do is use a property accessor such the dot or the bracket notation, to coerce the string value &lt;code&gt;“I am a string”&lt;/code&gt; to a &lt;code&gt;String&lt;/code&gt; object.:&lt;/p&gt;

&lt;p&gt;&lt;code&gt;“I am a string”.charAt(3) //  “a”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;It is also important to know that primitive values are immutable, so what is happening in background is that the string is temporarily converted to a &lt;code&gt;String&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;new String(“I am a string”).chartAt(3) //  “a”&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;in the example above, the &lt;code&gt;String ()&lt;/code&gt; function is called a “constructor function” since its name starts with a capital letter.&lt;br&gt;
Having the &lt;code&gt;new&lt;/code&gt; operator in front of a constructor function, will create a new object. &lt;/p&gt;

&lt;p&gt;In our case here, &lt;code&gt;String()&lt;/code&gt; is JavaScript built-in constructor (or object).&lt;/p&gt;

&lt;p&gt;That’s why you can also use a constructor functions to make objects instead of using object literal as show in the example below:&lt;/p&gt;

&lt;p&gt;Object literal :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var myCar = {
    make: 'Ford',
    model: 'Mustang',
    year: 1969
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Constructor functions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;function Car(make, model, year) {
  this.make = make;
  this.model = model;
  this.year = year;
}

var mycar = new Car('Ford', 'Mustang', 1969);// same object as mycar in object literal

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

&lt;/div&gt;



&lt;p&gt;Read more about constructor functions &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Working_with_Objects#using_a_constructor_function"&gt;here&lt;/a&gt; or String object &lt;a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String"&gt;here&lt;/a&gt; and if you have any suggestions or feedback, feel free to leave them below.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>primitives</category>
      <category>objects</category>
    </item>
    <item>
      <title>Things I learned this week.</title>
      <dc:creator>Hozan</dc:creator>
      <pubDate>Sat, 17 Apr 2021 17:04:34 +0000</pubDate>
      <link>https://dev.to/hozan/things-i-learned-this-week-5a7k</link>
      <guid>https://dev.to/hozan/things-i-learned-this-week-5a7k</guid>
      <description>&lt;p&gt;Before we go into the topic I want to first introduce myself as this is my first blog post on here. I am an aspiring web developer, who aims to be a junior developer by the end of the year. I started my coding journey in Autumn last year when I joined a brilliant non-profit organisation called CodeYourFuture, and today I will publish some thoughts and tips I learnt during the week, which I believe can give a little of help to people who are on the same journey as me.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;Why Soft skills are important?&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just remember this “Hard skills will get you the interview, but Soft skills will get you the job”,  this is one of the things I have learned from the people in the industry and thanks for coming to my Ted talk. &lt;/p&gt;

&lt;p&gt;But no seriously, Soft skills are skills that relates to your personal skills such as communications skills, teamwork, leadership, open-mindedness and the list goes on.&lt;/p&gt;

&lt;p&gt;Enhancing your Soft skills should take the same effort as your Hard skills (technical skills), because when recruiters wanna hire you as a junior, it is not because of your tech skills (as you do not have the experience yet), it is because they want to hire someone who thinks and behaves like a programmer and this is where you can use your Soft skills to demonstrator this, and I heard this directly myself from the senior developers/managers who work in well known companies.&lt;/p&gt;

&lt;p&gt;You might be also surprised that leaderships is among those skills that are deemed important for a junior to possess. Well first let me tell you that you do not need to lead a group of developers and mentor them to be regarded as a leader. &lt;/p&gt;

&lt;p&gt;Leadership is about learning from your mistakes and taking the necessary steps to overcome challenges, anything that challenges your inner self for the better good is a sign of leadership, deciding to advocate some time to enhance your skills is a sign of leadership, being honest and confident is a sign of leadership.&lt;/p&gt;

&lt;p&gt;There are a lot of skills that are categorised under Soft skills signs, quick online search about them will tell you what they are and how to improve them. This &lt;a href="https://pointjupiter.com/soft-skills-software-developer-need-ultimate-guide/"&gt;link&lt;/a&gt; is a page that explores Soft skills more in depth. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;A tip I got on how to get my first dev role.&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I got the following advice from a person who works in the recruitment agency,&lt;br&gt;
and what she suggested is to connect with and speak to the right people on LinkedIn.&lt;/p&gt;

&lt;p&gt;The best way to utilize this is to speak with people from the internal team, such as “Talent manager", "Head of people", "internal recruiter" "Recruitment manager" "Resourcing advisor".&lt;/p&gt;

&lt;p&gt;The method to use is to message/email them directly and make a tailored message for each message/email you send, as it will show them how much interest and effort you are putting in to get a job with them.&lt;/p&gt;

&lt;p&gt;Please feel free to share your suggestions or feedback if you wish. &lt;/p&gt;

</description>
      <category>softskills</category>
      <category>tips</category>
    </item>
  </channel>
</rss>
