Category 'Articles'

Just some of the things that go through my head...

JavaScript quirks – equality operators and comparisons

Articles, JavaScript

JavaScript – developers either love it or hate it and it’s not that difficult to see why. It’s a slightly different way of thinking from C# or Java development. All of a sudden semi-colons are optional, variables are in global scope and your functions have become objects and not just methods in a Class.

When does 0 == “”?

One of the main differences between C# and Java, is that JavaScript features weak typing. This means that the equality operator coerced types to compare them. This can be a total nightmare for an inexperienced JavaScript developer as the “==” operator can yield some really peculiar results. For example:

""          ==   "0"         // returns false
0           ==   "0"         // returns true
0           ==   ""          // returns true
false       ==   "false"     // returns false
false       ==   "0"         // returns true
false       ==   undefined   // returns false
false       ==   null        // returns false
null        ==   undefined   // returns true
" \t\r\n"   ==   0           // returns true

Interesting eh? So in JavaScript, the use of == is widely regarded as bad practice, and because of the coercion between its operands it has the potential to introduce bugs that will be frustrating to find. Luckily there is a better way…

The Strict Equality Operator

The strict equality operator is made up of three equals signs (===). It works a lot like the usual double equals (==) operator that we use in C# and Java, but in JavaScript it does not perform coercion between its operands. Now our equality comparisons perform as expected:

""         ===   "0"          // returns false
0          ===   ""           // returns false
0          ===   "0"          // returns false
false      ===   "false"      // returns false
false      ===   "0"          // returns false
false      ===   undefined    // returns false
false      ===   null         // returns false
null       ===   undefined    // returns false
" \t\r\n"  ===   0            // returns false

In Summary

So as you can see from the examples above, it’s much safer to use the strict equality operator in your JavaScript code. Ultimately, it will cut accidental mistakes that are cause JavaScript’s types coercion. For more detailed explanation on this and some of the other quirks in JavaScript, check out JavaScript Garden as it really is a great resource.

Continue Reading

Why web developers and web designers should join Twitter

Articles, Personal Opinion, Twitter

Twitter is nothing new. It’s now over 5 years old, and with over 1 billions tweets sent every week, it’s obvious that many of us are engaging regularly with the service. It’s home to many creative professionals, web designers, and web developers, with more and more signing up every day. It’s a great place for engaging and collaborating with the web development community, as well as great place for newer developers and designers to ask for guidance and share useful resources.

My experience with Twitter

I’ve been using Twitter for around 6 months at the time of writing this, and it’s no secret I love it. I’m spend most of my days encouraging people in the office to sign-up as I truly believe most developers will find it as useful as I do. There are many reasons to use Twitter, but for me, here are the primary ones.

Sharing Resources

There are loads of good resources and tutorials out there, it’s just a matter of finding them. My RSS feed used to be my main source of information and in fairness it did a pretty good job of keeping me up to date. Eventually though, my feed started to become more like a chore. After just a few days away from my computer, I could literally have hundreds of articles to sift through.

I think the way Twitter handles resource subscribing is a big improvement on RSS. I follow the my favourite design and development magazines on Twitter and their tweets appear in my timeline. If I miss something, then I don’t really care. I know if it’s a post that is that important someone I follow will most likely re-tweet the same link later on.

Ask & Give Advice

Nobody knows everything, and the even the best developers and designers can sometimes feel the need to ask for help. Whether it be feedback on a design, or advice on using a particular framework or CMS, you can be sure there is someone on Twitter that can give you a hand, or at the very least point you in the right direction. There is a sense of community between users, and you there are many experienced professionals out there who are more than willing to help you.

Finding Work

If you’re looking for a job, or if you’re a freelancer be sure to follow design agencies in your area. Most agencies tend to advertise their vacancies on Twitter before they go to the recruitment sites, so it’s always a good place to start.

Freelancers play a big part in the creative community as well. I know plenty who put work each others way when there is part of project out with their skill-set. Engaging regularly with freelancers and agencies is a great way to build up a relationship with them, don’t be shy and talk to them!

Keep Up To Date

Twitter is probably my main source of information these days. If something big happens on the news, the Twitter is the first place to find out about it. The same goes for web developments, if there is a security issue with a plugin you’ve used in an earlier project, you’ll more than likely be told via Twitter.

Make friends

New to the industry? Twitter is a great place to meet people just like you. There are plenty of meet-ups like the Rookie Oven meet-up in Glasgow, or the Twit-Ayr meet-up that are all run and scheduled through Twitter. Don’t be shy, add new friends, and talk to people. The more friends you make, the more you’ll get out of Twitter.

Distractions

There is always a downside, and in Twitter’s case it is that it can be very distracting. If you’re working in an office environment there is nothing more distracting than tweets popping up every 30 seconds. My advice would be to set your feed to update once an hour, as that really does help with your productivity. It also means you have a reason to stop for a couple of minutes every hour :)

So there you have it, why not give it a shot? If you do use twitter, be sure to add me (@rossg997) and say hello.

Continue Reading