javascript top 10 tricks and tips for beginner

mdimranul haque
3 min readMay 5, 2021

____________________________________________________________

javascript is one of the most popular programming language.javascript is easy to learn . here I will share most amazing 10 tips for you. lets start……

javascript is turning 25 years.

1) “spread’ operator”

we can use it to create new arrays with the combinations of more arrays. just like this …….

when,

const asdf=[1,2,3,4,5,6]

const fghj=[7,8,9,10]

if we went to connect of both in a array , its time to use spread operator .

just like this-

const combination = […asdf,….fghj]

Note- here we use (…) is called spread operator.

that's the use of spread operator.

2)”Convert to string”

how to convert a number into a string?

its so easy , just use “” after declear a variable . than it will return as a string type. lets see…….

var asdf=1

console.log(typeof(asdf)) =? and: number .

but,if we set a blank (+””) after declear a variable it will return as a string. wow that’s amazing .

Proved,

var asdf= 1;

asdf=1 + “”

console.log(typeof(asdf))=? and: string.

3)convert to number?

its also easy task, just do it in your code ,

var asdf =”15"

consle.log(typeof(asdf))=? and: string.

but ,

if we set a “” before “15” ? what will be the result??

lets see,,,

var asdf=”15"

aasf=”” + “15”

console.log(typeof(asdf)) =? , and: number.

wow , that’s awesome.

4)Difference between == and ====?

== operator an automatic type conversion if needed. but === will not perform any conversion.

its compares the value and type both. and faster than ==.

  • * == convert the values of the same type before testing they are same but=== not. that’s the difference.

it’s need to clear concepts before apply. i hope we understand this concepts.

5)How to create random number?

its so easy to do. just apply math.random .

than we get random number.

give a try.. like this……………..

console.log(Math.random())

run this ,, it will return always random number. ….

how funny .

6)To lowercase to uppercase-

The toUpperCase() method converts a string to uppercase letters.

the toLowerCase() method to convert a string to lowercase letters.

like this code-


var asdf = "Hello coders";
var asdfUpppercase= asdf.toUpperCase();
console.log(asdfUppercase);
=> HELLO CODERS.
var asdf = "HELLO CODERS";
var asdlowercase= asdf.toLowerCase();
console.log(asdlowercase);
=> hello coders.

7)charAt() method-

This method takes in a string and an index as input and returns the character at that position in the specified string-

like this code -

var str = “HELLO WORLD”;
var res = str.charAt(4);
console.log(res)
=>o

8) endWith() method

This method returns true if the string ends with the characters, and false if not. The endsWith() method is case sensitive also.

code line this -

“Hello coder”.endsWith(“coder”);//true “Hello "coder”.endsWith(“Hi”);//false

9)trimEnd()

trimEnd used to remove whitespace characters from the end of a string.

just like this..

const str = ‘ imran ‘; const result = str.trimEnd();
=> ' imran'

10)trimStart()

trimStart used to remove whitespace characters from the start of a string.

just like this..

const str = ‘ imran ‘; const result = str.trimEnd();
=> 'imran '

this is the end of this blog for now. however, it will update soon.

--

--

mdimranul haque
0 Followers

Web developer | programmer | learner