what is 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.
example:
let name= "bob";
console.log(typoeof name);
name=5
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
Pros:
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.
Cons:
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.
Top comments (0)