10 facts about Javascript
Published: 2021-05-05 13:57:42


1.Character access in string
There are two way to access characters of the string, one is using charAt()
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wc0ppo9rl2316nb62pgl.JPG)

The other way is just like an array-like object to access each character of the string.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/n1is75g7ooppr8kdz3qa.JPG)

2.Find the index of string
By using the indexOf() function we can easily find the first matching index number of a string. This function mainly return the index of the first matching string.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xjz8jesud0x4r5zwb2f8.JPG)

3.Changing the case of a string.
If we want to convert an upper case letter into a lower case then we dont have to convert it by using ASCII value like in C. Javascript has two beautiful function to do that toUpperCase() convert lower case letter into upper case and toLowerCase() do the reverse of toUpperCase().
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sks8243ndz24s9hdyeru.JPG)

4.String to integer/float
There are two functions in javascript which allow us to parse a string into an integer or float in one second which is parseInt() and parseFloat().
parseInt() take two parameters first one is the string and the second one is the base of the number system while parseFloat() do it for only the decimal number system and take only one parameter.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qoisnzq0ykmso6b7wpit.JPG)

5. Random numbers in javascript
Math.random() return a floating number range from 0 to less than 1. So if we want any fixed ranged random number than we have to multiply Math.random() with what we want. Suppose if we want a random number from 1 to 6 than we can do this
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lyx1ckrwahce2y7jiael.JPG)

6.Loop over an array
If we want to access each element of an array then we can use forEach() loop which is much easier and shorter than for loop.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u4z70mkozijwf53r1ckt.JPG)

7.Inserting element and removing element from the array
Using push() we can insert a new element in the array and by pop() we can remove the last element from the array
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/evz9novlbvn1sjawfwer.JPG)

8.Difference between find() and filter() 
By using filter() we get a portion of that array but using find() we get an element.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mpqv13pbk4y9y8zzh44h.JPG)

9.Difference between slice() and splice()
The slice() method returns the selected items as a new array object and don’t change the original array while splice() method returns the original array with removed items.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y55trl03i6kmfzuaasea.JPG)

10. Difference between shift() and unshift()
The shift() method remove an element at a specific position and shifts the remaining elements up while returns the removing element In the meantime unshift() exactly done the opposite thing it adds an element at a specific position and shifts the remaining element down and return the size of the array.
![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s2gqzm33c2e0qobfp3jz.JPG)