Array or object : how to choose … nail or screw ? TLDR Here is how I choose : Array are not associative in javascript. Array have some facility function (indexOf, foreEach, etc) Note: bonus there is pretty always a Polyfill for them (so don’t hesitate to use them in any browser) Object can be used as associative array. And Object can have function (methods), and constructor (sort of : using function constructor)

Continue reading

False assumption You may have heard : “Like in Python : everything in JavaScript is an Object” → ☹ WRONG ! … for Python it’s true (and for Ruby too), but not for javascript. No it’s a bit more complex for JS. Javascript types There are 7 types, and object has 5 differents kinds : Number ! ATTENTION ! : may be NaN (Not a Number) String Symbol (new in ES6) Boolean Null Undefined Object Function Array Date Error RegExp So Number, String, Symbol, Boolean are not object.

Continue reading

… yes every time a longer title What we want A tidy JS code = clean global scope = well organized functions in boxes (modules) independant. What is Cross-Reference problem ? Cross-reference in JS is when you accidentally override a function or variable ; because there is another function or variable with the same name. Cross-reference can be frequent in javascript, because it just has function isolation. So a variable in global scope is not safe, and you must keep the number of global variable as low as possible.

Continue reading

AJAX the Good (Asynchronous) Way TL;DR : Javascript and AJAX are asynchronous, so your code must be asynchronous✶ too ! ✶: JS is event driven, which is some kind of asynchronous, and AJAX is asynchronous Be carefoul : Never, never use synchronous AJAX request !!! It will make your apps feels laggy, and on bad network it can be unusable : because 1 long request block the main loop and all processing is blocked too.

Continue reading

Is JS pass-by-reference or by value ? TL;DR JS use pass by value for primitive and by reference for object and array (simplification inside). So how to : Copy a (not nested) array : var my_copy = my_array.slice(0); // ATTENTION : works for not nested array ! Cloning a (not nested) object : (look here for source + polyfill for obj.assign()) var my_obj = { a: 1 }; // If you don’t have nested object !

Continue reading

Javascript for Beginner 1 This is a first post of a little serie : my steps to explain to colleague new to javascript what to know and how to develop app without (too much) headache. The first thing I explain to someone new to javascript : the unusual way JS variables (var) are scoped, and the (bad) consequence. Javascript is function scoped What does that mean exactly. Well usually (in other language) variables are block scoped.

Continue reading

Author's picture

Tristan Giovangrandi

Happy Web developper @Content-Square and happy father

Full Stack & Embedded

France - Paris