Monday, October 22, 2012

Basic Syntax and Grammar

Basic Syntax & Language grammar

Let me start with explaining what does language grammar means to me, It means to understand the keywords, symbols, pre defined methods, system calls and their usage. It matches closely with what we call as syntax in general, for example:

() = is used to define a function
{} = is used to define what the function will contain
; = Defined the end of line for the code
var = defines the symbol

As we see it can be classified as syntax usually though the whole package of these are referred as the language grammar for that programming language, Learned this when i was reading turing machine lesson in my graduation years.

So now to the point of my learning JavaScript: It has seemed pretty straight forward to learn the basic syntax that is how to do the basic hello world, It is interesting to find static and dynamic control way of doing this i.e.

document.writeln = static type of definition
alert = A bad pop out way of static definition
document item properties = Wow this is pure dynamic way of moving things around with script.

The better part is the script definition can be embedded in pure html page or called out from inside the html file to keep a central script for all your pages. Created all the three examples for hello world, pretty quick as it goes. Sample code for dynamic way (Skipping the static ones as don't like that way with dynamic scripting :p ) , Save this as html for quick check

<html>
<Head> Sabby learning scripting <br> </head>
<body>
<div id=dynHello></div>
<script type='text/javascript'>
document.getElementById('dynHello').innerHTML='<p>Hello World!</p>'
</script>
</body>
</html>

That's it, the way to define a tag, call for the tag and define the html at runtime. Amazingly simple and quick

So overall got my basics of language to create the script tag, understand the way the language works in basic and got a hold of basic syntax. Rolling on to next topic

~Sabby


No comments:

Post a Comment