常量变量赋值

Assignment to constant variable

我尝试阅读用户输入并将其作为电子邮件发送。 但是当我 运行 这段代码时,它给了我这个错误: Assignment to constant variable.

任何帮助将不胜感激

var mail= require('./email.js')
var express = require('express')
var router = express.Router()

router.post('/',function(req, res, next){
    var address = req.fields.address
    var text = req.fields.text
    var subject = req.fields.subject

    try{
       if(text = 0){
           throw new Error('Please enter what u want to say')
       }
       if(subject = 0){
           throw new Error('Please enter subject')
       }

    }catch(e){
        req.flash('error', e.message)
        return res.redirect('back')
    }

    var detail = {
        to:address,
        text:text,
        subject:subject,
        from: 'test <nbuudilc@126.com>'
    }

    email(detail).then(function(){
        req.flash('success','email sent success')
        res.redirect('/posts')
    })

})

module.exports = router

您可能想要:

if (text == 0)

和:

if (subject == 0)

或:

if (!text)

和:

if (!subject)

我认为后一种选择更好,至少在风格上是这样。