Hybrid Posted April 27, 2006 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! Link to comment Share on other sites More sharing options...
Bluecrest Posted April 27, 2006 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 Link to comment Share on other sites More sharing options...
Err Posted April 27, 2006 Share Posted April 27, 2006 whoops. My bad. Link to comment Share on other sites More sharing options...
scott100 Posted April 27, 2006 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!") Link to comment Share on other sites More sharing options...
Kosher Kid Posted April 27, 2006 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 ; Link to comment Share on other sites More sharing options...
scott100 Posted April 27, 2006 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. Link to comment Share on other sites More sharing options...
Kosher Kid Posted April 27, 2006 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. Link to comment Share on other sites More sharing options...
aleksanteri Posted April 27, 2006 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 Link to comment Share on other sites More sharing options...
Kosher Kid Posted April 27, 2006 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! Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now