top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration

How to Swap a value using De Structuring in JavaScript (ES6)?

0 votes
How to Swap a value using De Structuring in JavaScript (ES6)?
posted Feb 27, 2018 by Sandeep Bedi

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Using de structuring we can easily swap a value without using any temporary variable.


var a = 10;
var b = 5;
[a,b] = [b,a]
answer Apr 30, 2018 by Chahat Sharma
Similar Questions
0 votes

I tried the following code.Both onpaste() and Oncopy() will trigger when user trying to copy or paste.

But my problem is while copying something window.getSelection() not working.

Window.getSelection() is used to get the selected data.

I mean before copying something user need to select some values.So,using this window.getselection() we will get the value what they are selected.

Here, my problem is window.getselection() will work in oncopy but not working in onpaste.

Check the below examples and help me to solve the problem.

Also ,is there any alternative method also please let me know.I also tried window.clipboardData.But not getting the solution for this.

<!doctype html>
    textarea {
        border:2px solid #999;

<script src=""></script>

    <script type="text/javascript">

        function OnPaste () {                                                                       
            var selection = window.getSelection();          
        function OnCopy() {         
            var selection = window.getSelection();

// Call the OnCopy function while user trying to copy 
document.oncopy = OnCopy;

// Call the OnPaste function while user trying to Paste
document.onpaste = OnPaste;

    Select some text, copy it to the clipboard and try to paste it to the following fields:
    <br /><br />
    <textarea size="40" value="Copy and Paste operation is enabled">
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.