Jump to content

How does a .js file look like???


Hybrid

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...