我使用eval函数插入相应旁白的值,我被卡在下面的代码中,请您摆脱此错误
var HeadMsg="ON CHEQUE CLEARANCE OF";
var pHead=" "+"PRINCIPAL COMPONENT";
var iHead=" "+"INTEREST COMPONENT";
var eHead=" "+"ON EMI NO";
var lHead=" "+"LOAN NO";
var $pricipal=" "+"1500";
var $interest=" "+"1000";
var $emino=" "+"1";
var $loanno=" "+"SCL2018000000000000000048";
var narr=HeadMsg +lHead + $loanno +pHead+ $pricipal +iHead+ $interest +eHead+ $emino;
var out=eval(narr);
console.log(out);
输出错误
检查未清贷款SCL2018000000000000000048主要成分1500利息成分1000符合EMI 1
VM512:1未捕获的语法错误:意外的标识符
答案 0 :(得分:0)
您甚至将eval用于什么?只是console.log(narr)会为您提供所需的输出。
答案 1 :(得分:0)
如果要输出给定的字符串,则可以简单地console.log
字符串:
var narr=HeadMsg +lHead + $loanno +pHead+ $pricipal +iHead+ $interest +eHead+ $emino;
console.log(narr);
或仅使用template literals并输出消息:
const principal="1500";
const interest="1000";
const emino="1";
const loanno="SCL2018000000000000000048";
console.log(`ON CHEQUE CLEARANCE OF LOAN NO ${loanno} PRINCIPAL COMPONENT ${principal} INTEREST COMPONENT ${interest} ON EMI NO ${emino}`);