Jump to content

Some Beginning Javascript Questions (really dumb probally)


walterb

Recommended Posts

Hey everyone,Im totally new to learning Javascript and have been learning it from here as well as webdevelopersnotes.com also and i have a few questions as im learning...Id greatly appreciate if someone could explain them in a very basic manner so that i could understand them!===============alert("He said \"JavaScript's the best!\"");Why Does the Above code not cause a Javascript Error Due to conflicting "" Marks at the end of the code? Im sure those backslashes have something to do with it and im aware of the special functions you can use with backslashes such as \t or \n but What Does a blank backslash due to make this code work?==================<script LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">Is this the ONLY Javascript Beginning code that is EVER used? I know that the script language is Always gonna be javascript but What about the type? Are there other types aside from "text/javascript"? ==================<script LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">document.write("I love JavaScript");Okay,So i know this is a VERY basic line of code that simply writes "i love javascript" into the window (without the quotes of course!) but Is this Code Ever USED? or is it to show an extremely basic function of javascript instead? How practicle IS Using code like this when you could instead just type I love javascript without the code and be done with it? ===================<A HREF="somelink.html" onmouseover="document.bgColor='#FF0000';window.status='Dangerous color'" onmouseout="document.bgColor='#FFFFEE'">Link</A>Okay,So the following code is supposed to display a new Background Color with mouseover with a different bg color on mouse out...When i tried it in Firefox this wasnt the case and the bg color didnt change...Is this code wrong? i didnt do it myself so i dont think so....Or am i missing something? Also where exactly is the "window status" bar on a browser? Is that the part at the bottom left corner that will display a new url With mouseover?===================Thats all i have for now,Im sure i'll come up with more soon! Thanks in advance for someones help!

Link to comment
Share on other sites

alert("He said \"JavaScript's the best!\"");Why Does the Above code not cause a Javascript Error Due to conflicting "" Marks at the end of the code? Im sure those backslashes have something to do with it and im aware of the special functions you can use with backslashes such as \t or \n but What Does a blank backslash due to make this code work?
That does not cause error because " are escaped with a \ which tells the interpreter to print a " and that is not the end of a stringJust like the \t and \n
<script LANGUAGE="JAVASCRIPT" TYPE="TEXT/JAVASCRIPT">Is this the ONLY Javascript Beginning code that is EVER used? I know that the script language is Always gonna be javascript but What about the type? Are there other types aside from "text/javascript"?
That is to distinguish javascript form other scripting languages
<script type="text/vbscript">

document.write("I love JavaScript");Okay,So i know this is a VERY basic line of code that simply writes "i love javascript" into the window (without the quotes of course!) but Is this Code Ever USED? or is it to show an extremely basic function of javascript instead? How practicle IS Using code like this when you could instead just type I love javascript without the code and be done with it?
For example you can write a function which will write good morning or good evening depending what time is it :) It is used on more complex things as well.
Link to comment
Share on other sites

That Helps out! Btw....On the first question of the alert box with double end quotes You answered:That does not cause error because " are escaped with a \ which tells the interpreter to print a " and that is not the end of a stringJust like the \t and \n And i still dont quite understand...What exactly Does "escaped" mean? Whats the interpeter? is that the browser? Why couldnt you just Use Single AND double Quotes like this to make the code work like other times and Just Get rid of those backslashes? Im still a very beginning so i dont understand Even Basic Termonology.

alert('He said "JavaScript's the best!"');

Also Whats the point of making a dead link? Why couldnt you just Not make a link to begin with? Is their some sort of advanced function To go with this somehow Or Some advantage? Of course this Does take you To a Page with a red background color but if your being practicle Then If a link went dead wouldnt u just fix it? Whats the point? Im talking about the following code example:

<A HREF="java script:void(0)"onmouseover="document.bgColor='#EEEEEE'">Dead link</A>

Link to comment
Share on other sites

And i still dont quite understand...What exactly Does "escaped" mean? Whats the interpeter? is that the browser? Why couldnt you just Use Single AND double Quotes like this to make the code work like other times and Just Get rid of those backslashes? Im still a very beginning so i dont understand Even Basic Termonology.
Interpreter is the engine(program) that executes the code (javascript in this case) without having to compile (convert to executable program) it. JavaScript interpreter is the browser.There are languages that in which programs wiritten are compiled to some executable code (.exe for example) and other languages (javascript, php, ....) where the code is interpreted (compiled and executed on-the-fly)Read more: http://en.wikipedia.org/wiki/Interpreter_%28computing%29When a string(text) is assigned to a variable or printed it should be enclosed in quotes, be it single or double quotes. But there are cases when the string itself contains quotes. It quotes are not escaped the compiler/interpreter would 'think' that there is the end of the string and an error will be shown. You can use either single quotes or double quotes to enclose the strings.The way you wrote the line below is wrong because the single quote in red is the end of the string and it must be escaped by adding a backslash before.alert('He said "JavaScript's the best!"');
Also Whats the point of making a dead link? Why couldnt you just Not make a link to begin with? Is their some sort of advanced function To go with this somehow Or Some advantage? Of course this Does take you To a Page with a red background color but if your being practicle Then If a link went dead wouldnt u just fix it? Whats the point? Im talking about the following code example:
<A HREF="java script:void(0)"onmouseover="document.bgColor='#EEEEEE'">Dead link</A>

Links in HTML are used to open another page which is specified in the href attribute of the link. So, by clicking on a link another page will be opened. There are cases when you want to associate an JavaScirpt action to a link, which will perform some operations on the current page and you want to keep the user in that page after clicking the link. This example changes the background color of the page. In order to stay on the current page instead of typing a url a dead link is used.
<A HREF="java script:void(0)" onmouseover="document.bgColor='#EEEEEE'">Dead link</A>

This means don't open another page, just change the color.

Link to comment
Share on other sites

Hi,well I'm a newbie as well in javascript. So I'm only able to answer your first question.You ask: Why Does the Above code not cause a Javascript Error Due to conflicting "" Marks at the end of the code?with following code:

alert("He said \"JavaScript's the best!\"");

Well following characters are condiderd as a command (no print-outs or displayed characters): \ " there may be others like them. (quotes is to dislpay a text)So to display a " or \ you have to use \ before these characters. Like follow\\\"Oh and with ' you can't display any text. You need to use "Hope this helps,greetz

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...