String.prototype.contains() ES6 browsers support a String.prototype.contains() method. But its not supported in older browsers still in use, such as Internet Explorer 11 and below, or Safari 7 and below. If you are still one of those browsers, we can use the following functions : indexOf() Output : string1 contains string2 search() We can …
Continue reading How to check if a string contains a substring in JavaScriptJavaScript
Nashorn engine Java 6 introduced a JavaScript engine called Rhino that enabled embedding JavaScript code in Java. In Java 8, a new JavaScript engine called Nashorn has been added that provides several new features. To obtain Nashorn engine, we need to create an instance of ScriptEngineManager and then pass the engine name in getEngineByName() …
Continue reading Running JavaScript from Java using Java 8 Nashorn engineArrow functions Arrow functions are, as the name suggests, functions defined with a new syntax that uses an arrow (=>) as part of the syntax. The arrow function definition consists of a parameter list followed by the => marker, which is followed by a function body. For example, Arrow functions are also known as Lambda …
Continue reading Arrow functions in JavaScriptScope In JavaScript, scope refers to the current context of code. A variable’s scope is the context in which the variable exists. The scope specifies from where you can access a variable and whether you have access to the variable in that context. In JavaScript, a variable can be globally or locally defined …
Continue reading JavaScript ScopeSwitch statement Switch statement starts with a variable called Switch value. This is the variable whose value if compared in each case statement within the switch. Each case statement indicates a possible value for the variable and subsequent code that should run if the variable matches the case value. Example of Switch statement …
Continue reading JavaScript Switch statement