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 :: date now js 
Javascript :: node require module 
Javascript :: javascript if object has key 
Javascript :: function currying javascript 
Javascript :: continuos scrollling js 
Javascript :: promisify 
Javascript :: axios post form data and json 
Javascript :: round number at 2 decimal places 
Javascript :: javascript function to open file browser 
Javascript :: set cookie in reactjs 
Javascript :: react native share image 
Javascript :: laravel send http post request json 
Javascript :: npm fund error 
Javascript :: bindparam 
Javascript :: angular passing data to child component 
Javascript :: chrome.storage.local get 
Javascript :: array map arrow function 
Javascript :: Execute JavaScript using Selenium WebDriver in C# 
Javascript :: js array add every element of array 
Javascript :: how to increment counter button click in js 
Javascript :: javascript check if url returns 200 
Javascript :: $q.platform.is.mobile 
Javascript :: js read xml file 
Javascript :: how to make a div appear when clicked on in javascript 
Javascript :: window load 
Javascript :: axios delete request payload 
Javascript :: empty function after it is run javascript 
Javascript :: js array last element get 
Javascript :: moment get day 
Javascript :: formgroup is not property of form angular 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =