In the previous chapter, we've seen a way to set up Coffee Script. On this chapter, let us take a look at out the syntax of Coffee Script.
Coffee Script Statements
not like many other programming languages like C, C++, and Java, the statements in Coffee Script do now not end with semicolons (;). in place of that, each new line is taken into consideration as a separate announcement via the Coffee Script compiler.
Right here is an example of a Coffee Script announcement.
In the same way, we can write two statements in a single line by separating them using semicolon as shown below.
While creating variables in CoffeeScript, there is no need to declare them using the var keyword. We can directly create a variable just by assigning a value to it as shown below.
In popular, we use parenthesis at the same time as declaring the function, calling it, and also to split the code blocks to avoid ambiguity. In CoffeeScript, there's no need to apply parentheses, and at the same time as creating functions, we use an arrow mark (->) in preference to parentheses as proven underneath.
Still, we have to use parentheses in certain eventualities. Whilst calling functions without parameters, we can use parentheses. For example, if we've got a function named my_function in Coffee Script, then we've to name it as proven under.
Within the equal manner, we also can separate the ambiguous code the use of parentheses. in case you study the following example, without braces, the result is 2233 and with braces, it is going to be 45.
Following is an instance of a characteristic in CoffeeScript. here you may look at that instead of curly braces, we've got used three whitespaces as indentation to separate the frame of the function.
In any programming language, we use comments to write a description about the code we've written. These remarks are not considered as the part of the applications. The remarks in Coffee Script are much like the comments of Ruby language. Coffee Script gives two sorts of comments as follows −
On every occasion we want to remark a single line in Coffee Script, we just need to place a hash tag before it as shown underneath.
Each single line that follows a hash tag (#) is taken into consideration as a comment by using the CoffeeScript compiler and it compiles the rest of the code inside the given report except the comments.
Every time we want to comment more than one line in Coffee Script (a couple of lines), we are able to do this by means of wrapping those strains within a couple of triple hash tags as proven below.
A list of all the reserved words in Coffee Script is given in the following desk. They can't be used as Coffee Script variables, functions, techniques, loop labels, or any item names.
CoffeeScript Related Interview Questions
|XML Interview Questions||HTML Interview Questions|
|HTML 5 Interview Questions||Oracle DBA Interview Questions|
|HTML DOM Interview Questions||Java Interview Questions|
|JBOSS Interview Questions||Java XML Interview Questions|
|ebXML Interview Questions||Unix/Linux Interview Questions|
|Xml Publisher Interview Questions|
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.