Explain Type Inference (Duck Typing) in C# ?
- By Shiv Prasad Koirala in C#
- Dec 27th, 2022
- 1363
- 0
Type inference refers to the automatic detection of the type of an expression in formal language. JavaScript is dynamic language and it checks its type in run time. Let we conclude from the given example.
- In the given example we firstly open a html template and we always write the JavaScript code inside the body tag as given below with tag because it gives the HTML time to load before any of the JavaScript loads, which can prevent errors, and speed up website response time.
- We declare the variable var x=10; we know x is number because it holds the numbered value but we can't declare that it is number in given JavaScript code then our JavaScript will automatically detect the type of that x variable by the behavior that it shows so this term is known as type inferences in simple word.
Let's we describe it more from taking another example having different datatype in same JavaScript code then we get the clear idea what it means.
Here are three variables x, y and a each of having different datatypes but we aren't declares their types but our JavaScript engine will automatically detect their types.As in given JavaScript we write number datatype in x variable x=10, y variable having string datatype y= "bikesh" and similarly, a variable having Boolean datatype a=true; according to this our JavaScript engine will show the output in console so this terms of automatically detecting the type of variables are known as type inference in JavaScript.
Shiv Prasad Koirala
Visit us @ www.questpond.com or call us at 022-66752917... read more