How to check whether a string contains a substring in JavaScript?

ECMAScript 6 introduced String.prototype.includes: const string = “foo”; const substring = “oo”; console.log(string.includes(substring)); // true includes doesn’t have Internet Explorer support, though. In ECMAScript 5 or older environments, use String.prototype.indexOf, which returns -1 when a substring cannot be found: var string = “foo”; var substring = “oo”; console.log(string.indexOf(substring) !== -1); // true

How to modify existing, unpushed commit messages?

Amending the most recent commit message git commit –amend will open your editor, allowing you to change the commit message of the most recent commit. Additionally, you can set the commit message directly in the command line with: git commit –amend -m “New commit message” …however, this can make multi-line commit messages or small corrections … Read more

How do I redirect to another webpage?

One does not simply redirect using jQuery jQuery is not necessary, and window.location.replace(…) will best simulate an HTTP redirect. window.location.replace(…) is better than using window.location.href, because replace() does not keep the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking … Read more

What does "use strict" do in JavaScript, and what is the reasoning behind it?

Update for ES6 modules Inside native ECMAScript modules (with import and export statements) and ES6 classes, strict mode is always enabled and cannot be disabled. Original answer This article about Javascript Strict Mode might interest you: John Resig – ECMAScript 5 Strict Mode, JSON, and More To quote some interesting parts: Strict Mode is a … Read more

How do I check if an element is hidden in jQuery?

Since the question refers to a single element, this code might be more suitable: // Checks CSS content for display:[none|block], ignores visibility:[true|false] $(element).is(“:visible”); // The same works with hidden $(element).is(“:hidden”); It is the same as twernt’s suggestion, but applied to a single element; and it matches the algorithm recommended in the jQuery FAQ. We use … Read more