I have a page http://www.sample.com/load.html ,which loads javscript file http://example.com/test.js which contains code for writing cookies on page , will I be able to create a cookie for http://www.sample.com.
CAn JS access the domain from where they are loaded or only those domain on which JS file is loaded?
Javascript can (with only a couple of exceptions such as CORS) only access the domain of the document. The origin of the Javascript is irrelevant.
So yes, in this case, you will be able to set cookies on
sample.combut not onexample.com, because the document issample.com. You can tell what the relevant domain is using thedocument.domainproperty.