Hybrid 0 Posted April 27, 2006 Report Share Posted April 27, 2006 Hi I know this might be a newbie question but I was wondering how a .js file would look like? It says in the tutorial that I can link files form outside if they end in .js, but I wanted to know do they look like an html file or like a script file: <script>Eerything in here</script> Thanks again for any help! Quote Link to post Share on other sites
Bluecrest 0 Posted April 27, 2006 Report Share Posted April 27, 2006 JS file is a javascript file. What you see in between <script></Script> in html should be the content of the JS file Quote Link to post Share on other sites
Err 10 Posted April 27, 2006 Report Share Posted April 27, 2006 whoops. My bad. Quote Link to post Share on other sites
scott100 1 Posted April 27, 2006 Report Share Posted April 27, 2006 Note: The external script cannot contain the <script> tag!wrong <script type="text/javascript">document.write("Hello World!")</script> correct document.write("Hello World!") Quote Link to post Share on other sites
Kosher Kid 0 Posted April 27, 2006 Report Share Posted April 27, 2006 Actually, I don't think any of your answers have been complete enough.A javascript file consists of functions which are then called from an html file. It is a plain text file that is saved with a .js extension.It is correct that no <script></script> tags are needed but function declarations are:function DoSomething() { statement; statement;}function DoSomethingElse (parameter) { statementuse (parameter);}etc...Each function must have the opening and closing brackets and each line should end with a ; Quote Link to post Share on other sites
scott100 1 Posted April 27, 2006 Report Share Posted April 27, 2006 A javascript file consists of functions which are then called from an html file.<{POST_SNAPBACK}> Actually an external script can contain information outsite of functions. Quote Link to post Share on other sites
Kosher Kid 0 Posted April 27, 2006 Report Share Posted April 27, 2006 quite right, but in my experience js files are primarily used to contain functions that can be used by multiple html files. Quote Link to post Share on other sites
aleksanteri 0 Posted April 27, 2006 Report Share Posted April 27, 2006 Actually I don't think that you need semicolons in external js files. But I use semicolons though. http://www.w3schools.com/js/js_howto.aspWith traditional programming languages, like C++ and Java, each code statement has to end with a semicolon.Many programmers continue this habit when writing JavaScript, but in general, semicolons are optional! However, semicolons are required if you want to put more than one statement on a single line.I have wrote C code (basic though) and I continue the habit because I need to learn more C and I don't want to forget the importance of the semicolons Quote Link to post Share on other sites
Kosher Kid 0 Posted April 27, 2006 Report Share Posted April 27, 2006 You are correct. Semi-colons are required for multiple statements on one line but not much else.Personally, I find it makes the code more readable and since other things, like CSS files require them, I find it is just a good habit to be in.Ultimately I was just trying to give the original question from Hybrid a more complete answer than he was getting...now he probably overwhelmed! Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.