
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 6710 Articles for Javascript

2K+ Views
Pass by value In pass by value, a function is called by directly passing the value of the variable as the argument. Changing the argument inside the function doesn’t affect the variable passed from outside the function. Javascript always pass by value so changing the value of the variable never changes the underlying primitive (String or number).In the following example, variable 'a' has assigned value 1. But inside function 'change' it got assigned with value 2. Since javascript is always a pass by value, the displayed output will be '1' but not '2'.ExampleLive Demo let a = 1; ... Read More

319 Views
There are two methods to merge properties of javascript objects dynamically. They are1) Object.assign() The Object.assign() method is used to copy the values of all properties from one or more source objects to a target object. It will return the target object.Example-1 Live Demo var target = { a: "ram", b: "rahim" }; var source = { c: "akbar", d: "anthony" }; var returnedTarget = Object.assign(target, source); document.write(JSON.stringify(target)); document.write(JSON.stringify(returnedTarget)); output{"a":"ram", "b":"rahim", "c":"akbar", "d":"anthony"} {"a":"ram", "b":"rahim", "c":"akbar", "d":"anthony"}If the objects have the same keys, ... Read More

3K+ Views
Non-enumerable propertyObjects can have properties that don't show up when iterated through the particular object using Object.keys() or for...in loop.Those type of properties are called as non-enumerable properties.Creating a non-enumerable propertyTo create a non-enumerable property we have to use Object.defineProperty() method. This a special method to create non-enumerable properties in an object. In the following example, three properties such as name, age and country were created normally and a property named "salary" was created using Object.defineProperty() method and key named enumerable was assigned with false. When the object "person" got iterated using Object.keys() the properties such as name, age and country ... Read More

394 Views
ECMAScript 5 has introduced several methods to prevent modification of object. Those preventive measures ensures that no one, accidentally or otherwise change functionality of object.There are 3 levels of preventive methods1) Prevent ExtensionsIn this level, one cannot add any new properties or methods but can access existing properties or methods. Here there is an ability to delete the respective object. Object.preventExtensions() is the method used to accomplish this task. It prevents any new properties from ever being added to the object.ExampleLive Demo var object1 = { prop1: 1 ... Read More

3K+ Views
A string is an order of one or more characters that contain numbers, letters, symbols, or special characters. In JavaScript strings are immutable. i.e., once you create a string you cannot change its value. For example, consider the following snippet here we have created a string variable and assigned a value (Tutorialspoint) to it. In the next statement, we are trying to change the contents of the string at the first index. Then we are displaying the contents of the string. let x = 'Tutorialspoint'; x[0] = 't'; console.log(x); //Tutorialspoint. On executing this code ... Read More

1K+ Views
Insertion Sort The Insertion Sort is a sorting algorithm that works very similar to the way we sort the playing cards when we play. The arrangement of elements in a sorted manner. In this algorithm, the array will be divide virtually into two parts which are sorted and unsorted parts. The values present in unsorted part will be pick and placed at the correct position where it satisfies the sorting order. The Insertion sort is simple algorithm having simple implementation. Generally, this algorithm is efficient for smart data values. This is suitable for data sets which are already partly ... Read More

10K+ Views
Title Case a sentence in javascriptIt is nothing but converting first element of all the words in a sentence in to uppercase while the other elements remain in lowercase. The provided string(sentence) may contains a bunch of lowercase and uppercase elements. So we need an algorithm to Title Case the provided string.AlgorithmDivide all the words in the sentence individually. This task can be achieved by using string.split() method.Convert all the elements in each and every word in to lowercase using string.toLowerCase() method. Loop through first elements of all the words using for loop and convert them in to uppercase. After converting, ... Read More

822 Views
Palindrome is a string that even when reversed will be the same as the original string. In simple words, the palindrome string will have odd length and the element in 0th index and the last index will be the same, element in 1st index will be the same as the second last element and so on. The palindrome contains alphanumeric elements; that means it contains the alphabet(a-z) and digits (0-9) as well. A palindrome string must look like − var str = "121Malayalam121"; Let’s understand with a suitable example. Let’s understand with a suitable example. Example 1 In the ... Read More

177 Views
Flattening an arrayFlattening an array is nothing but merging a group of nested arrays present inside a provided array. Flattening of an array can be done in two ways. 1) concat.apply() In the following example there are some nested arrays containing elements 3, 4, 5 and 6. After flattening them using concat() method we get the output as 1, 2, 3, 4, 5, 6, 9. Example Live Demo var arrays = [1, 2, [3, 4, [5, 6]], 9]; var merged = [].concat.apply([], arrays); documemt.write(merged); Output1, 2, 3, 4, 5, 6, 92) array.flat()In ... Read More

5K+ Views
Given an array, and generate the random permutation of array elements. It is similar like shuffling a deck of cards or randomize an array and every outcome after shuffling of array elements should likely and equally. Input output scenarios Consider an array having some elements present in it and assume we have performed fisher yates shuffle on that array. The output array will be randomly shuffled and shuffles for every time we execute. All the permutations are equally and likely. Input = [2, 4, 6, 8, 10] Output = 4, 10, 6, 2, 8 // first iteration ... Read More