Why is +1 + 23 + 4 in JavaScript?

Arjun Thakur
Updated on 24-Jun-2020 06:41:33

103 Views

The JavaScript's + operator is used to add two numbers or join two strings. However, use the contact() method to join two arrays to get a new one. For example,[50, 70].concat([90, 100])The above prints,[50, 70, 90, 100]Let’s see your example. The + operator concats strings, and converts the arrays to strings −[1,2] + [3,4] '1,2' + '3,4' 1,23,4Or as mentioned above, use concat(),[1,2].concat([3,4]) [1,2,3,4]

Use JavaScript Array.sort() Method for Shuffling

Nikitha N
Updated on 24-Jun-2020 06:40:54

97 Views

Yes, you can use the JavaScript Array.sort() method for shuffling. Let’s see howExamplefunction shuffleDisplay(arr) {    var tmp, current;        // calculating length    var top = arr.length;    if(top) while(--top) {       current = Math.floor(Math.random() * (top + 1));       tmp = arr[current];       arr[current] = arr[top];       arr[top] = tmp;    }    return arr; }

Fix Array indexOf in JavaScript for Internet Explorer Browsers

Ramu Prasad
Updated on 24-Jun-2020 06:37:02

461 Views

To fix Array.indexOf() for Internet Explorer web browser, use the following −jQuery.inArray( value, array [, fromIndex ] )Add the following,

Convert Image to Base64 String Using JavaScript

Arjun Thakur
Updated on 24-Jun-2020 06:36:26

620 Views

To convert the image into a base64 string using JavaScript, use the FileReader API. You can try to run the following code to get base64string for an image −Example                    function toDataURL(url, callback) {             var httpRequest = new XMLHttpRequest();             httpRequest.onload = function() {                var fileReader = new FileReader();                   fileReader.onloadend = function() {                      callback(fileReader.result);                   }                   fileReader.readAsDataURL(httpRequest.response);             };             httpRequest.open('GET', url);             httpRequest.responseType = 'blob';             httpRequest.send();          }          toDataURL('https://www.tutorialspoint.com/videotutorials/images/tutor_connect_home.jpg', function(dataUrl) {          document.write('Result in string:', dataUrl)       })          

Set CSS Style for Element When Animation is Not Playing

Arjun Thakur
Updated on 24-Jun-2020 06:35:03

119 Views

Use the animation-fill-mode property to set a style for the element when the animation is not playingExampleLive Demo                    div {             width: 150px;             height: 200px;             position: relative;             background: red;             animation-name: myanim;             animation-duration: 2s;             animation-fill-mode: backwards;          }          @keyframes myanim {             from {left: 0px; background-color: green;}             to {left: 200px; background-color: blue;}          }                        

Print Double Value with Full Precision using cout in C++

Arjun Thakur
Updated on 24-Jun-2020 06:34:50

2K+ Views

The output stream cout allows using manipulators that you can use to set the precision directly on cout and use the fixed format specifier. To get the full precision of a double, you can use the limits library. For example,Example#include #include using namespace std; int main() {     // Get numeric limits of double     typedef std::numeric_limits< double > dbl;     double PI = 3.14159265358979;     cout.precision(dbl::max_digits10);     cout

Difference between Private, Public, and Protected Modifiers in C++

Nikitha N
Updated on 24-Jun-2020 06:33:56

7K+ Views

Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled access modifiers − public, private, and protected sections within the class body.The default access for members and classes is private.Exampleclass Base { public:    // public members go here protected:    // protected members go here private:    // private members go here };A public member is accessible from anywhere outside the class but within a program. ... Read More

Select All Elements with CSS

Chandu yadav
Updated on 24-Jun-2020 06:33:47

273 Views

To select all elements, use the * CSS Selector. You can try to run the following code to select all the elements,ExampleLive Demo                    *{             color: blue;             background-color: orange;          }                     Demo Website       Learning       Tutorials on web dev, programming, database, networking, etc.       Every tutorials has lessons with illustrations and figures.    

Select Elements Whose Attribute Value Begins With a Specified Value with CSS

Ankith Reddy
Updated on 24-Jun-2020 06:33:03

186 Views

To select elements whose attribute value begins with a specified value, use the [attribute^=”value”] selectorYou can try to run the following code to implement the [attribute^=”value”] selector,ExampleLive Demo                    [alt^=Tutor] {             border: 5px solid blue;             border-radius: 5px;          }                              

Select Element with ID using CSS

Nancy Den
Updated on 24-Jun-2020 06:32:27

172 Views

To select all the elements with id=”tutorials”, you can try to run the following code.Use the #id CSS selector to achieve this,ExampleLive Demo                    #tutorials {             border: 3px solid red;          }                     Tutorialspoint       Learning       Tutorials on web dev, programming, database, networking, etc.       Every tutorials has lessons with illustrations and figures.    

Advertisements