Variable assignment in JavaScript

var num1 = 10;
var num5 = 40;

num1=num2=num3=num4=num5;
 
console.log("Value of num1", num1);
console.log("Value of num2", num2);
console.log("Value of num3", num3);
console.log("Value of num4", num4);
console.log("Value of num5", num5); 
 
Question: What is the value of num1, num2, num3, num4 and num5?
Answer: 40 Assignment is done from right to left.

Comments

Popular posts from this blog

Inserting and Moving elements inside Ruby Array

Interview Question on Ruby on Rails