简体   繁体   English

如何为嵌套(?)常量定义测试,JavaScript

[英]How to define test for nested(?) const, JavaScript

I'm using javascript for the first time in a work setting, and have to test a code running within our questionnare solution.我第一次在工作环境中使用 javascript,并且必须测试在我们的问卷解决方案中运行的代码。 The answers can only be true or false, and the check is written like this:答案只能是真或假,支票是这样写的:

if(Page.Group.Question.Answer){*do something*};

In my test-code I have to define Page.Group.Question.Answer myself and I can't seem to find out how to do it, although I am sure it is quite easy.在我的测试代码中,我必须自己定义 Page.Group.Question.Answer 并且我似乎无法找到如何去做,尽管我确信这很容易。 I have tried the following so far:到目前为止,我已经尝试了以下方法:

var Page.Group.Question.Answer = true;

and

let Page.Group.Question.Answer = true;

And then I tried to define a const, but I couldn't find out how it should be nested.然后我尝试定义一个 const,但我不知道它应该如何嵌套。

What is the correct syntax?什么是正确的语法?

With some help from Jaromanda X and deceze the answer is that I need to define it as:在 Jaromanda X 和 deceze 的帮助下,我需要将其定义为:

const Page = {Group: {Question: {Answer: true}}}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM