JavaScript: Upload file

Pure JS You can use fetch optionally with await-try-catch Show code snippet Old school approach – xhr Show code snippet SUMMARY In server side you can read original file name (and other info) which is automatically included to request by browser in filename formData parameter. You do NOT need to set request header Content-Type to multipart/form-data – this will be set automatically by … Read more

What does this symbol mean in JavaScript?

See the documentation on MDN about expressions and operators and statements. Basic keywords and general expressions this keyword: How does the “this” keyword work? var x = function() vs. function x() — Function declaration syntax var functionName = function() {} vs function functionName() {} (function(){…})() — IIFE (Immediately Invoked Function Expression) What is the purpose?, How is it called? Why does (function(){…})(); work but function(){…}(); doesn’t? (function(){…})(); vs (function(){…}()); shorter alternatives: !function(){…}(); – What … Read more

Node.js – SyntaxError: Unexpected token import

Node 13+ Since Node 13, you can use either the .mjs extension, or set {“type”: “module”} in your package.json. You don’t need to use the –experimental-modules flag. Modules is now marked as stable in node.js Node 12 Since Node 12, you can use either the .mjs extension, or set “type”: “module” in your package.json. And you need to run node with the –experimental-modules flag. Node 9 In Node 9, it is enabled behind a flag, and … Read more

What does “javascript:void(0)” mean?

The void operator evaluates the given expression and then returns undefined. The void operator is often used merely to obtain the undefined primitive value, usually using “void(0)” (which is equivalent to “void 0”). In these cases, the global variable undefined can be used instead (assuming it has not been assigned to a non-default value). An explanation is provided here: void operator. The reason you’d want to … Read more

What’s the difference between event.stopPropagation and event.preventDefault?

stopPropagation prevents further propagation of the current event in the capturing and bubbling phases. preventDefault prevents the default action the browser makes on that event. Examples preventDefault stopPropagation With stopPropagation, only the button‘s click handler is called while the div‘s click handler never fires. Where as if you use preventDefault, only the browser’s default action is stopped but the div’s click handler still … Read more

Generating random whole numbers in JavaScript in a specific range?

There are some examples on the Mozilla Developer Network page: Here’s the logic behind it. It’s a simple rule of three: Math.random() returns a Number between 0 (inclusive) and 1 (exclusive). So we have an interval like this: Now, we’d like a number between min (inclusive) and max (exclusive): We can use the Math.random to get the correspondent in the [min, max) interval. But, first we … Read more

What is the meaning of == $0 that is shown in inspect element of google chrome for the selected element [duplicate]

Dev Tools remembers the last five DOM elements (or JavaScript heap objects) that you’ve selected in the tab (or Profiles panel). It makes those objects available as $0, $1, $2, $3, and $4. $0 returns the most recently selected element or JavaScript object, $1 returns the second most recently selected one, and so on. See this for more information.

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