+ 7
Why JS is loosely typed? Explain with an example.
8 Answers
+ 5
I agree with Lisa F.
In the early years of HTML, web pages were quite static in the browser with all logic residing within the web server application.
Netscape originally created Javascript as "a 'glue language' that was easy to use by Web designers and part-time programmers to assemble components such as images and plugins, where the code could be written directly in the Web page markup." - Wikipedia (JavaScript)
This aligned with a concept at the time known as Dynamic HTML (DHTML) which focused on bringing simple UI/design functionality to web content that was predominantly being built by web designers, who had little to no programming experience. At that time, programmers worked on desktop or server applications.
As we have seen, things have changed over the years and now we have large, feature rich, full scale applications written in Javascript that run in browsers, as well as, servers, desktops, and mobile devices.
+ 9
Programming languages can be strong or loose type. Loose type could be prone to errors, developers need a better test functions, but it builds coding more faster and easily.
JavaScript can be written in strong type by using Typescript. Some developers especially larger scale application development or angular developers use Typescript to write codes.
+ 7
My impression was that it is loosely typed to save programming time given javascript's primary function is to manipulate content and styles on a web page and content on a web page is inherently text. It was supposed to be a simpler language focused on the problem of users interacting with a web page. But it has obviously grown beyond its initial role!
For example if you are working on a web page shopping cart and the user types in 2 in a quantity input box you can go ahead and multiply with that number even though everything that is entered on a web page is a string.
But I guess we would have to ask Brendan Eich to know for sure why he created JavaScript as a loosely typed language!
+ 4
My impression was that loosely (or weakly) typed refers to variable types (i.e. string, integer, float, etc.) as opposed to variable availability.
Broadly:
https://www.quora.com/Why-is-JavaScript-considered-a-loosely-typed-language
Short:
https://www.computerhope.com/jargon/l/looslang.htm
Long:
https://medium.com/@xiaoyunyang/javascript-is-a-loosely-typed-language-meaning-you-dont-have-to-specify-what-type-of-information-137408d54fc7
+ 4
Lisa F I'd ask for sure iff I get a chance to meet with Brendan Eich..;)
+ 3
CalviŐ˛ Could you explain , how it'd help to build coding more faster and easily?
+ 2
1) suppose If you declare a variable without a "var" keyword then the variable is available globally
2) hoisting - variable can be used before its declaration
So javascript is loosely typed
+ 2
You might also find this article interesting:
https://codeburst.io/strict-types-typescript-flow-javascript-to-be-or-not-to-be-959d2d20c007