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 :: how to convert integer to double in javascript 
Javascript :: how to increment counter button click in javascript 
Javascript :: click counter in js 
Javascript :: how to break the foreach loop in javascript 
Javascript :: joi unique validation 
Javascript :: JavaScript Create Multiple Objects with Constructor Function 
Javascript :: count down timer in react native 
Javascript :: accessing object properties with bracket notation 
Javascript :: javascript set input value 
Javascript :: toarray javascript 
Javascript :: dom element set id 
Javascript :: loop through an array in js 
Javascript :: laravel http send data json raw 
Javascript :: get timezone name from date javascript 
Javascript :: axios fetch 
Javascript :: adb reverse USB debugging 
Javascript :: convert associative array to json javascript 
Javascript :: jquery equivalent of document.getelementbyid 
Javascript :: this setstate previous state react 
Javascript :: nodejs for windows 7 
Javascript :: nodejs routes 
Javascript :: jQuery onclick not firing on dynamically inserted HTML elements 
Javascript :: tailwind config for nextjs 
Javascript :: response.json() promise pending 
Javascript :: remove json javascript 
Javascript :: checkbox default value and checked value get in jquery 
Javascript :: mongodb find all that dont have property 
Javascript :: node js event emitter 
Javascript :: javascript class methods 
Javascript :: namespace in javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =