Important Topics of JavaScript You Must Know :- Part-1

Image for post
Image for post
Photo by Shahadat Rahman on Unsplash

1. Difference Between String.charAt() and String.indexof()

2. How String.split() and String.slice() works.

3. Difference Between String.substr() and String.substring().

4. Math.ceil() , Math.floor() , Math.round () which one to use.

5. uses of isNaN() , parseInt() and parseFloat()

6. Difference Between Array.find() and Array.filter().

7. Array.ForEach() the Ultimate version of For loop

8. Array.map() the gangstar

9. Array.reduce() makes life easy for math

10 . Confusion between Array.slice() Array.splice() and easy solution.

1. Difference Between String.charAt() and String.indexof()

  • what the String.charAt() does is returns a new string consisting of the single value what we pass through this methods.
  • It only gives us only one character of the whole string.
  • where String.indexof() can give us the index of a particular word and if we have the same value of word in the string many times we can retrieve that value also
  • charAt() have only one parameter which is index but indexof() have two parameter , search value and fromIndex , fromIndex is optional.
Image for post
Image for post

2. How String.split() and String.slice() works.

  • The String.split() method divides a String.split() into an ordered list of substrings, puts these substrings into an array, and returns the array. The division is done by searching for a pattern; where the pattern is provided as the first parameter in the method's call.
  • In easy word split() method just split the string into pieces with the condition what we give and then give them as a array of string.
  • The slice() method extracts a section of a string and returns it as a new string, without modifying the original string.
  • slice() method takes two parameter as a arguments and give a fresh new array after completed the task.
  • we can use slice() method by giving only one parameter also and it will splice after the whole value what we give it to…
Image for post
Image for post

3. Difference Between String.substr() and String.substring().

  • The String.substr() method returns a portion of the string, starting at the specified index and extending for a given number of characters afterwards.
  • The String.substring() method returns the part of the string between the start and end indexes, or to the end of the string.
  • The difference between them two is that substr() takes two arguments and one is start index from where we start to and the number of word or letter we want from the string
  • On the other hand substring() also takes two arguments but one is start index from where to we want the value and the end index till we want.
  • The similarity is both of them also works fine with one arguments and they works also same… from that one arguments we will get all the value after that value.
Image for post
Image for post

4. Math.ceil() , Math.floor() , Math.round () which one to use.

  • The Math.ceil() function always rounds a number up to the next largest integer.
  • The Math.floor() function returns the largest integer less than or equal to a given number.
  • The Math.round () function returns the value of a number rounded to the nearest integer.
  • In this three methods we can use all of them by our choice and needs when we need to rounds a number to minimum level we can use Math.floor() ,when we need to rounds a number to maximum level we can use Math.ceil()
  • On the other hand we can use to avoid fixed condition that which one is nearest value for the fraction value it can be floor or ceil it depends on the value. if it will above ≥ 50 then it will perform ceil() method and less then 50 will perform floor() method.
Image for post
Image for post

5. Uses of isNaN() , parseInt() and parseFloat()

  • The isNaN() function determines whether a value is NaN or not. It return a boolean value true or false.
  • The parseInt() function parses a string argument and returns an integer
  • The parseFloat() function parses an argument (converting it to a string first if needed) and returns a floating point number.
  • In the time of using parseInt() or parseFloat(), accidently or intentionally if we give a string value to them instead a number or float value it will give us NaN . that means Not A Numer
Image for post
Image for post

6. Difference Between Array.find() and Array.filter().

  • The Array.find() method returns the value of the first element in the provided array that satisfies the provided testing function.
  • The Array.filter() method creates a new array with all elements that pass the test implemented by the provided function.
  • if we somehow give the same instruction for the two of this methods we will get different value from the two method
  • imagine in a array we have three 11 and all other value are divided by 2 . if we asking for prime number with find() we will get only 11 but with filter we will get 3 of 11.
Image for post
Image for post

7. Array.forEach() the Ultimate version of For loop

  • The Array.forEach() method executes a provided function once for each array element.
  • if we were familiar with for loop then we knew that for loop is a cool thing huh ?? when it comes the time for doing a thing again and again then comes the need for for loop…
  • with for loops our life gets easier but with forEach() method life gets more flexible more easier
  • it syntax is easier looks cool less to write easy to understand
Image for post
Image for post

8. Array.map() the gangstar

  • The Array.map() method creates a new array populated with the results of calling a provided function on every element in the calling array.
  • above i talk about how for loop works and how forEach() makes easier for us
  • Now i will say Array.map() make life more then forEach() method and how it happends ?? let’s talk about that
  • we can use for loops and forEach easily for array… and in case of iteration on object inside an array they got stuck … it this case Array.map() comes with a bang and it can do what those can do and can do more than that
Image for post
Image for post

9. Array.reduce() makes life easy for math

  • The Array.reduce() method executes a reducer function (that you provide) on each element of the array, resulting in single output value.
  • In case of math when we want to calculate a value , a whole value like sum
  • we need to write a lot’s of code and that’s time consuming here comes the reducer methods
  • Your reducer function’s returned value is assigned to the accumulator, whose value is remembered across each iteration throughout the array, and ultimately becomes the final, single resulting value.
Image for post
Image for post

10 . Confusion between Array.slice(), Array.splice() and easy solution.

  • The Array.slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
  • The Array.splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place
  • Array.slice() just cut the array and make a new array with the value
  • Array.splice() method can replace value of a specific place of an array or can remove that value
Image for post
Image for post

That’s it for Today see you in the next Article…. Till Then Stay Well

Currently I’m working with M E R N stack. I love to learn new technology and explore them. I’m a simply simple person with lots of interests.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store