DEV Community

Cover image for Dynamic typing in Javascript

Posted on

Dynamic typing in Javascript

what is dynamic typing ?

Dynamic typing

Javascript is a dynamic typing language. When you declare a variable, you do not need to specify what type this variable is. Javascript engine infers what type this variable is based on the value assigned to at run time.


let name= "bob";
console.log(typoeof name);


console.log(typeof name);

firstly, the variable was a string and now it is of number datatype.
same thing can be done with null and undefined as well nd amongst any datatypes for that matter of fact.

Pros and Cons of Dynamic typing in JavaScript


1.Deals naturally with certain types of self-describing data.
2.Code can be use polymorphically without programmer decoration.
3.Tends to reduce unnecessary clutter and duplication/repetition in code.


1.More errors detected later in development and in maintenance.
2.More errors at runtime and in shipped code.
3.Tends to prohibit compilation and yields poor performing code.
4.Need to write entirely mechanical tests for type correctness.

Discussion (0)