var variable = 10;
function start() {
variable = 20;
}
console.log(variable + 20);
// Answer will be 40 since the variable was changed in the function
Quas: HOW TO CHANGE OR UPDATE Variable VALUE in javascript?
Ans: To change something First write the element
Then the name and position of that element
Then write that position with equal sign Then write what you want to change.
example:
I have taken a variable which contains some names,Among these names I will change the name Rasel.Now we need to find out the index number of this Rasel,
then we can change the name with the index number. Anything can be changed by this rule.*/
var friendsName = ['habib', 'iqbal', 'shorif', 'asraful', 'rasel', 'arif', 'deader' ];
var positionIndex = friendsName.indexOf('rasel'); /* find index number */
console.log(positionIndex); /* for output index number */
/* output index number
PS C:javascript> node ans.js
4
PS C:javascript> node ans.js */
friendsName[4] = 'saiful'; /* change this index number name */
console.log(friendsName); /* for output index number */
/* output change with this name
PS C:javascript> node ans.js
[
'habib', 'iqbal',
'shorif', 'asraful',
'saiful', 'arif',
'deader'
]
PS C:javascript> */
// 5 is assigned to variable x
let x = 5;
console.log(x); // 5
// vaue of variable x is changed
x = 3;
console.log(x); // 3