javascript - Multiplying a letter by a number -
trying around javascript code looking at. seeing things this:
var myvariable = "x"; var result = myvariable * 6;
coming c# background, new me. give me quick primer on going on here? guessing result equal letters position in alphabet multiplied 6, correct?
i guessing result equal letters position in alphabet multiplied 6, correct?
no. js weakly typed, , values implicitly typecasted match operator (a multiplicative one here). in case, string "x"
converted number - leading nan
it's no valid numberic literal. result
nan
well.
to position in alphabet, you'd use parseint
function non-decimal base (parseint("x", 36)-10
) or charcodeat
string method ("x".charcodeat(0)-65
).
Comments
Post a Comment