# Reuse JavaScript Code Across Obsidian Notes
_February 21, 2024_
Obsidian plugins like [[Obsidian Dataview|Dataview]] make it possible to write JavaScript code directly inside Markdown notes to do amazing things, like [[Obsidian for Meal Planning|meal planning]]. When using the same code across multiple notes, it's important not to duplicate the code. If I was using a DataviewJS code block on 10s or 100s of notes and found a bug or a possible improvement, I wouldn't want to have to edit all those notes individually.
## Dataview and Custom Views
The [[Obsidian Dataview|Dataview plugin]] offers a simple way to reuse JavaScript across multiple notes:
- [`dv.view(path, input)`](https://blacksmithgu.github.io/obsidian-dataview/api/code-reference/#dvviewpath-input)
Place your reusable JavaScript files in your vault, they can either return a Markdown string or use the [`dv` API](https://blacksmithgu.github.io/obsidian-dataview/api/code-reference) (like [`dv.header(level, text)`](https://blacksmithgu.github.io/obsidian-dataview/api/code-reference/#dvheaderlevel-text) or [`dv.list(elements)`](https://blacksmithgu.github.io/obsidian-dataview/api/code-reference/#dvlistelements)).
For example:
```js
// File: views/custom.js
return `## Header\n\nInput is ${JSON.stringify(input)}`;
```
Or:
```js
// File: views/custom.js
dv.header(2, "Header);
dv.paragraph(`Input is ${JSON.stringify(input)}`);
```
- `dv` is a special variable giving access to the Dataview API.
- `input` is a special variable giving access to arguments passed to the view (optional).
You are ready to use the following code block in your notes:
````
```dataviewjs
await dv.view("views/custom", { arg1: "foo", arg2: "bar" });
```
````
The result, when the note is rendered, should look something like:
---
## Header
Input is {"arg1":"foo","arg2":"bar"}
---
For a practical application of this technique, see [[Obsidian for Meal Planning]].