Home > Mobile >  Identifier expected error with multi line string
Identifier expected error with multi line string

Time:04-01

enter image description here

I'm working with node , trying to build jupyter notebooks programatically. I'm trying to create a function that will build a notebook 'code' type cell. After working in the repl I have:

function codeCell(arr =>  
  `{
  cell_type: 'code',
  execution_count: null,
  metadata: { tags: [] },
  outputs: [],
  source: [${arr}]
}`
);

As you can see in the screenshot I'm getting an identifier expected error. What am I doing wrong?

CodePudding user response:

function codeCell(arr =>  

You started defining an arrow function inside the argument list of a function definition, which is invalid syntax.

Either write

function codeCell(arr) {
  return `{
    cell_type: 'code',
    execution_count: null,
    metadata: { tags: [] },
    outputs: [],
    source: [${arr}]
  }`;
}

Or if you want to use the arrow function syntax:

const codeCell = (arr) => `{
  cell_type: 'code',
  execution_count: null,
  metadata: { tags: [] },
  outputs: [],
  source: [${arr}]
}`;
  • Related