Pass variables by reference in JavaScript

There is no “pass by reference” available in JavaScript. You can pass an object (which is to say, you can pass-by-value a reference to an object) and then have a function modify the object contents: function alterObject(obj) { obj.foo = “goodbye”; } var myObj = { foo: “hello world” }; alterObject(myObj); alert(myObj.foo); // “goodbye” instead … Read more

What’s the scope of a variable initialized in an if statement?

Python variables are scoped to the innermost function, class, or module in which they’re assigned. Control blocks like if and while blocks don’t count, so a variable assigned inside an if is still scoped to a function, class, or module. (Implicit functions defined by a generator expression or list/set/dict comprehension do count, as do lambda … Read more

python: how to identify if a variable is an array or a scalar

>>> import collections.abc >>> isinstance([0, 10, 20, 30], collections.abc.Sequence) True >>> isinstance(50, collections.abc.Sequence) False note: isinstance also supports a tuple of classes, check type(x) in (…, …) should be avoided and is unnecessary. You may also wanna check not isinstance(x, (str, unicode)) As noted by @2080 and also here this won’t work for numpy arrays. … Read more

Declaring multiple variables in JavaScript

The first way is easier to maintain. Each declaration is a single statement on a single line, so you can easily add, remove, and reorder the declarations. With the second way, it is annoying to remove the first or last declaration because they start from the var keyword and finish with the semicolon respectively. Every … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)