DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Curious about the future of data-driven systems? Join our Data Engineering roundtable and learn how to build scalable data platforms.

Data Engineering: The industry has come a long way from organizing unstructured data to adopting today's modern data pipelines. See how.

Threat Detection: Learn core practices for managing security risks and vulnerabilities in your organization — don't regret those threats!

Managing API integrations: Assess your use case and needs — plus learn patterns for the design, build, and maintenance of your integrations.

Avatar

Jeremy Martin

Joined Mar 2008

Stats

Reputation: 0
Pageviews: 65.5K
Articles: 2
Comments: 11
  • Articles
  • Comments

Articles

article thumbnail
Understanding Loose Typing in JavaScript
for many front end developers, javascript was their first taste of a scripting and/or interpretive language. to these developers, the concept and implications of loosely typed variables may be second nature. however, the explosive growth in the demand for web 2.0-ish applications has resulted in a growing number of back end developers that have had to dip their feet into pool of client side technologies. many of these developers are coming from a background in strongly typed languages, such as c# and java, and are unfamiliar with both the freedom and the potential pitfalls involved in working with loosely typed variables. since the concept of loose typing is so fundamental to scripting in javascript, an understanding of it is essential. this article is a top level discussion of loose typing in javascript. since there may be subtle differences in loose typing from language to language, let me constrain this discussion to the context of javascript. ok, let's dig in... what is loose typing? well, this seems like a good place to start. it is important to understand both what loose typing is , and what loose typing is not . loose typing means that variables are declared without a type. this is in contrast to strongly typed languages that require typed declarations. consider the following examples: /* javascript example (loose typing) */ var a = 13; // number declaration var b = "thirteen"; // string declaration /* java example (strong typing) */ int a = 13; // int declaration string b = "thirteen"; // string declaration notice that in the javascript example, both a and b are declared as type var. please note, however, that this does not mean that they do not have a type, or even that they are of type "var". variables in javascript are typed, but that type is determined internally. in the above example, var a will be type number and var b will be type string. these are two out of the three primitives in javascript, the third being boolean. javascript also has other types beyond primitives. the type diagram for javascript is as follows (as per mozilla ): ya really - null and undefined too. note, however, that this distinction between primitives and objects will be dismissed in javascript 2.0. you can read more about that here . type coercion type coercion is a topic that is closely associated with loose typing. since data types are managed internally, types are often converted internally as well. understanding the rules of type coercion is extremely important. consider the following expressions, and make sure you understand them: 7 + 7 + 7; // = 21 7 + 7 + "7"; // = 147 "7" + 7 + 7; // = 777 in the examples above, arithmetic is carried out as normal (left to right) until a string is encountered. from that point forward, all entities are converted to a string and then concatenated. type coercion also occurs when doing comparisons. you can, however, forbid type coercion by using the === operator. consider these examples: 1 == true; // = true 1 === true; // = false 7 == "7"; // = true 7 === "7"; // = false; there are methods to explicitly convert a variable's type as well, such as parseint and parsefloat (both of which convert a string to a number). double negation (!!) can also be used to cast a number or string to a boolean. consider the following example: true == !"0"; // = false true == !!"0"; // = true conclusion this obviously is not a definitive reference to loose typing in javascript (or type coercion for that matter). i do hope, however, that this will be a useful resource to those who are not familiar with these topics, and a good refresher for those who already are. i have tried to insure that the above is accurate, but if you notice anything incorrect, please let me know! and as always, thanks for reading!
March 14, 2008
· 14,912 Views
article thumbnail
Easy Multi Select Transfer with jQuery
I'm sure that at some point or another you've encountered a form widget like the one below, allowing options to be traded from one multi select to another. Option 1 Option 2 Option 3 Option 4 add >> << remove I recently encountered a tutorial over at Quirks Mode on creating such a widget. While not a bad script, when all was said and done it was coming up on 40 lines of JS. I suppose that's not horrible, but we're talking about some simple functionality. This struck me as a perfect example to demonstrate the simple and compact nature of jQuery coding. The widget operating above is running off of the following code: $().ready(function() { $('#add').click(function() { return !$('#select1 option:selected').remove().appendTo('#select2'); }); $('#remove').click(function() { return !$('#select2 option:selected').remove().appendTo('#select1'); }); }); That's it... 8 lines. You can also try it out for yourself with the following test page: Option 1 Option 2 Option 3 Option 4 add >> << remove Since the purpose of this widget is usually to collect all the elements in the second multi select, you can use the following snippet to automatically select all of the options before submitting. $('form').submit(function() { $('#select2 option').each(function(i) { $(this).attr("selected", "selected"); }); }); Just make sure you include that snippet inside the $().ready() handler. Thanks for viewing and I hope you found this helpful! Feel free to use and modify without constraint.
March 7, 2008
· 31,171 Views

Comments

Jquery UI makes things easy.

Jul 27, 2009 · Xavier Typendorf

[Some Title Everyone will Click On Here] [Ramble a bit here] [P.S. Real reason I wrote this article here]
Easy Multi Select Transfer with jQuery

Mar 08, 2008 · Jeremy Martin

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
Easy Multi Select Transfer with jQuery

Mar 08, 2008 · Jeremy Martin

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
Easy Multi Select Transfer with jQuery

Mar 08, 2008 · Jeremy Martin

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
Easy Multi Select Transfer with jQuery

Mar 08, 2008 · Jeremy Martin

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
NASCAR Tech Habits Stress Data Sharing And Security Best Practices > Share Data Effectively to Empower Teams

Mar 08, 2008 · Lebon Bon Lebon

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
NASCAR Tech Habits Stress Data Sharing And Security Best Practices > Share Data Effectively to Empower Teams

Mar 08, 2008 · Lebon Bon Lebon

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
NASCAR Tech Habits Stress Data Sharing And Security Best Practices > Share Data Effectively to Empower Teams

Mar 08, 2008 · Lebon Bon Lebon

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
NASCAR Tech Habits Stress Data Sharing And Security Best Practices > Share Data Effectively to Empower Teams

Mar 08, 2008 · Lebon Bon Lebon

I just read through your article. I liked your integreation of the Selso plugin - keeping the options sorted is definitely a selling point.
NASCAR Tech Habits Stress Data Sharing And Security Best Practices > Share Data Effectively to Empower Teams

Mar 07, 2008 · Lebon Bon Lebon

Well thank you and I certainly take that as a complement. I would love to see it in use!
Easy Multi Select Transfer with jQuery

Mar 07, 2008 · Jeremy Martin

Well thank you and I certainly take that as a complement. I would love to see it in use!

User has been successfully modified

Failed to modify user

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: