Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to change a variables value in javascript

var variable = 10;

function start() {
  variable = 20;
}
console.log(variable + 20);

// Answer will be 40 since the variable was changed in the function
Comment

change value of variable javascript

 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>  */
Comment

JavaScript Change the Value of Variables

// 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
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript Implicit Conversion to String 
Javascript :: javascript Convert to Number Explicitly 
Javascript :: ternary operator multiple conditions 
Javascript :: truthy or falsy 
Javascript :: javascript Create Objects: Constructor Function Vs Object Literal 
Javascript :: JavaScript Precision Problems 
Javascript :: javascript arrow function syntax 
Javascript :: javascript WeakMaps Are Not iterable 
Javascript :: javascript Error handling is easier to manage 
Javascript :: javascript variable name arguments and eval are not allowed 
Javascript :: JavaScript Object Prototypes 
Javascript :: javascript even/uneven numbers 
Javascript :: jQuery Traversing - Ancestors 
Javascript :: javascript get days difference between two dates 
Javascript :: Could not resolve "i18n-iso-countries" 
Javascript :: javascript read all cookies 
Javascript :: how to generate random 6 digit charecter in js for coupon 
Javascript :: phaser create animation on sprite 
Javascript :: append input using js 
Javascript :: remove text and keep div inside a div jquery 2 
Javascript :: get random item in array 
Javascript :: javascript change IFormFile to base64string 
Javascript :: javascript show alert if browser is not google chrome 
Javascript :: ... in javascript 
Javascript :: js filter example 
Javascript :: react native icons 
Javascript :: vue sidebar 
Javascript :: how to do division in javascript 
Javascript :: play sound onload react 
Javascript :: object.assign 
ADD CONTENT
Topic
Content
Source link
Name
5+5 =