0

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?

3
  • This is called a "template literal", not multi-line string. Commented Mar 31, 2022 at 18:00
  • It looks like your IDE doesn't recognize ES6 features like arrow functions and template literals. Make sure you've configured the proper JavaScript version. Commented Mar 31, 2022 at 18:01
  • @Barmar , Thank you. I'm using vscdode and made some changes following code.visualstudio.com/docs/nodejs/… Commented Mar 31, 2022 at 18:57

1 Answer 1

3
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}]
}`;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.