Back to functions

nerdamer.setVar


setVar

Sets a known value in nerdamer. This differs from setConstant as the value can be overridden trough the scope. See example. Set to "delete" or "" to unset

Usage: nerdamer.setVar(variable_name, value)


Parameters

String name The known value to be set
Number|Expression|string value The value for the expression to be set to.

Returns

nerdamer

EXAMPLES:
nerdamer.setVar('x', '11');
var x = nerdamer('x*x');
console.log(x.toString());
//nerdamer will use 13 instead of 11
x = nerdamer('x*x', {x: 13});
console.log(x.toString());
//the value will be 121 again since the known value isn't being overridden
x = nerdamer('x*x');
console.log(x.toString());
nerdamer.setVar('x', 'delete');
//since there no longer is a known value it will just be evaluated symbolically
x = nerdamer('x*x');
console.log(x.toString());
OUTPUT:
Back to functions