Here I will describe the way of including a JavaScript file in another JavaScript file. Because sometimes we need dynamic loading of JavaScript, may be based on some condition. In Css, We have already @import to include one css file into another.
Search Results » javascript
How to detect the screen resolution with javascript
In javascript, the screen.width and screen.height properties contain the size of a visitor’s monitor is set to. Bear in mind that the size of the monitor is set to, is not the same as the size of the browser window a visitor is using as windows can of course be set to different sizes. To get screen resolution with javascript we need to get the height and width of the viewport which depends on browser.
Function Declaration vs Function Expression in JavaScript
There are different ways to define a function in javascript. I have seen these 2 ways to define and get confused with the differences than I googled and came across with some points which can help out to others to understand the difference between these.
JavaScript String substr() Method
The substr() method returns the characters in a string beginning at the specified location through the specified number of characters. Syntax, parameters, examples of substr() in Javascript are as below.
JavaScript String substring() Method
substring() is one of the main string function which is mostly used in javascript. The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string.
4 ways to empty an array in JavaScript
JavaScript arrays are commonly used by developers and making them empty is also used in practice. Here I am describing 4 ways to empty an array in JavaScript:
1. Use splice() method
2. Set length to zero
3. Using pop() method
4. Set array to new empty array
Getting query string values in javascript
Sometimes we get the important data through query string but question is of getting query string values in javascript or jquery because we need these values at client side. Even we can do it by using only javascript also.
Validate email address in jQuery or JavaScript
Form validation is essential part of programming. We can validate email address in jQuery or JavaScript using regular expression. In this article, both are explained. You can check the live demo as well.
Add and Remove Classes using JavaScript
Add and Remove Classes using JavaScript is quite handy. Even it’s better to use a JavaScript framework or a library for such common tasks and I have mentioned the reason behind doing so at the end of article, these JavaScript code to adding and removing classes are worth considerable.
Array in JavaScript – push() Method
Array in JavaScript push() method appends the given element or elements in the last of array. It returns the length of the new array.
Syntax is as below:
array.push(item1, item2,.....itemN);