OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How can we assign values for multiple variables at once, is it possible only if it is an object?

  • Thread starter Thread starter sudarsan
  • Start date Start date
S

sudarsan

Guest
Code:
const object4={
  message:'Good Job',
  price:799
}
const {message,price}=object4;
console.log(message)
console.log(price)

In this code we are assigning the value 'Good Job' to the variable message and 799 to price.

When I try to do the below code it shows an error:

Code:
const {a,b}=1,2;

console.log(a)

the output for this line is

SyntaxError: Unexpected number

What should I do?

<pre><code>const object4={
message:'Good Job',
price:799
}
const {message,price}=object4;
console.log(message)
console.log(price)
</code></pre>
<p>In this code we are assigning the value <code>'Good Job'</code> to the variable <code>message</code> and <code>799</code> to <code>price</code>.</p>
<p>When I try to do the below code it shows an error:</p>
<pre><code>const {a,b}=1,2;

console.log(a)
</code></pre>
<p>the output for this line is</p>
<blockquote>
<p>SyntaxError: Unexpected number</p>
</blockquote>
<p>What should I do?</p>
 

Latest posts

Top