Parsing a string to a date in JavaScript

The best string format for string parsing is the date ISO format together with the JavaScript Date object constructor. Examples of ISO format: YYYY-MM-DD or YYYY-MM-DDTHH:MM:SS. But wait! Just using the “ISO format” doesn’t work reliably by itself. String are sometimes parsed as UTC and sometimes as localtime (based on browser vendor and version). The best practice should always … Read more

Best way to store a key=>value array in JavaScript?

That’s just what a JavaScript object is: You can loop through it using for..in loop: See also: Working with objects (MDN). In ECMAScript6 there is also Map (see the browser compatibility table there): An Object has a prototype, so there are default keys in the map. This could be bypassed by using map = Object.create(null) since ES5, but was seldomly done. … Read more

How can I convert a string to boolean in JavaScript?

Do: using the identity operator (===), which doesn’t make any implicit type conversions when the compared variables have different types. Don’t: You should probably be cautious about using these two methods for your specific needs: Any string which isn’t the empty string will evaluate to true by using them. Although they’re the cleanest methods I can think of concerning … Read more

What are the difference between $(document).bind(‘ready’, function) and $(document).ready(function() {})

The difference is, as the docs say There is also $(document).on( “ready”, handler ), deprecated as of jQuery 1.8. This behaves similarly to the ready method but if the ready event has already fired and you try to .on( “ready” ) the bound handler will not be executed. Ready handlers bound this way are executed after any bound by the … Read more

ajax jquery simple get request

It seems to me, this is a cross-domain issue since you’re not allowed to make a request to a different domain. You have to find solutions to this problem: – Use a proxy script, running on your server that will forward your request and will handle the response sending it to the browser Or – … Read more

What does the className attribute mean in JSX?

className is used instead of class in JSX because class is a JavaScript keyword. All JSX gets turned into vanilla JavaScript. If you wrote class it would try to make a JavaScript class and not make an element that has a class. So, when you write react it looks like this. Then something like babel will take that code and turn it into vanilla JavaScript: … Read more

Remove properties from objects (JavaScript)

To remove a property from an object (mutating the object), you can do it like this: Demo For anyone interested in reading more about it, Stack Overflow user kangax has written an incredibly in-depth blog post about the delete statement on their blog, Understanding delete. It is highly recommended. If you’d like a new object with all the keys of the original … Read more

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