Jump to content

How does a .js file look like???


Recommended Posts

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...