Some jS functions showcased here are not real functions in other programs


#1

So i have recently started using codecademy to learn code. I used notepad++ before and I still like to use it as a way to write up my code. So when I learn something new here I usally mess around with it in notepad++ but then i soon realized that common functions used here do not work in the real world. Like console.log does not print anything in notepad++, but instead document.write is used. So i don't understand why we're being taught false code, can anyone explain why this is? Why can't the devleopers or creaters just change console.log to document.write?


#2

This is not 'false code' as you suggest. It is code written in the debugging console, something most browsers have in the Developer Tools section. There is no HTML document object in the terminal environment of the JavaScript console, only a command line and interpreter/compiler and a display.

We can be glad at the end of the JavaScript track for having had plenty of practice in the debugging console. It will be our go to resource more often than not, even when we embark on DOM manipulation in webpages. The console is where we find error messages and with the command line can query our program variables, run individual functions and perform all manner of debugging. Relish in it.


#3

Thanks mtf, but see I am not farmilliar with most of the terms you stated here since i'm still in highschool and I am a newbie at javascript. I have a brief idea of what the debugging console is, but then i dont understand why I am being taught document.write if console.llog is the way to go, is there ONE right way or are their multiple or it just depends on who you ask, could you just simply your answer so a begineer like me can understand. Thanks for the reply I get the jist of what you'r saying.
P.S what the heck is DOM


#4

I don't recall document.write being taught here. That would imply a web page which we do not have in these lessons. Not until we get to the jQuery track do we write for that medium.

We should not confuse console.log() with production coding. It is NOT used in a page facing the web (or a normal browser window). It is only used in the terminal environment we are presently in. As you will find out eventually, document.write is quite outdated, as well, so we won't be using it much, ever. There are other ways, but going into them now would just be a distraction.

If you have not studied HTML and CSS yet, then I would recommend you begin with that as soon as you can. HTML, CSS and JavaScript are the core API languages for browsers. They work together harmoniously by not getting in each other's way.

HTML   =>  document structure
CSS    =>  presentation
JS     =>  behavior

Nothing helps with building our vocabulary better than reading. Lots of reading. Like learning anything, very little sticks at first, so repetition is essential, whether reading or doing. Search for 'document object model` and begin going through the search results. You'll learn more from that than having me give you a pared down explanation.


#5

Thanks mate, I am taking a course in High school at the moment, and I am learning javascript (but I like to come here to pracitise, to you know stay ahead). That's what I meant by " i don't understand why I am being taught document.write". So I understand that to write to the web, you use document.write and console.log is used in "the terminal enivironment". So i guess the application I use to write up code (notepad++) does not support console.log, since it is an application used to write to the web.

Thanks for the answer man/woman

P.S: You should become a philosopher or something, your words have deep meaning!


#6

You have the terminal environment on your system: JavaScript Console in the tools section of your browser. It has no editor or other IDE components. Only the command line and the terminal display (as well as the JavaScript interpreter/compiler).

You can write code in Notepad++, save it, and copy it to the command line and enter it into memory. If the code is all functions, then it will need to be invoked. If it is in command form it will execute immediately. Function code remains in memory, as well as any global variables created by your code. This is what makes it an ideal debugging environment.

document.write is considered obtrusive since it must appear inline in the HTML source. That's why it has gone the way of the Dodo. We have better ways to inject content into the DOM from within our external script. Modern standards abhor script in HTML.


#7

I really need to search those terms up, like you suggested earlier. So document.write has been tabooed due to its obtrusive ways. Thanks again for the answers. I wont bug you anymore :smile:


#8

No problem. That's what I'm here for. Ask anything you like. Never 'bugs' me, ever. Better you are informed, or guided to answers you seek.