Does it matter where require
is put within a file? This is using duktape to use js function in my android app.
For Example:
some javascript code
var calc = require('calculate')
Then call calc.calculate
I normally would declare calc first such as
var calc = require('calculate')
some javascript code
Does this make any difference in JS??
require
is a function, you can call it anywhere within your JavaScript file.
It's typically used at the top of a file because it's useful to see the file's dependencies all in one place, but it's not necessary.
Note that require
has very different semantics than JavaScript's own import
, and import()
, which will eventually replace require
.