`let x=1` and `const x=1` don't work.
Author: ahuigoCreated Dec 22, 2023Updated Jan 31, 2025
Labelshelp wanted
package m
import (
"fmt"
"testing"
"github.com/robertkrimen/otto"
)
func TestEvalJs(t *testing.T) {
vm := otto.New()
vm.Set("body", `{"page":1}`)
v, err := vm.Run(`
let abc = 2 + 2;// Not work here
console.log("The value of abc is " + abc); // 4
`)
if err != nil {
fmt.Printf("%+v, val:%v", err, v)
}
}I find another lib which supports const/let: https://github.com/dop251/goja
Source: robertkrimen/otto