1) Explain what is CoffeeScript?
CoffeeScript is a small programminglanguage that compiles
into JavaScript. It helps to write JavaScript code better by providing you with
a more consistent syntax and avoiding the irregular nature of JavaScript
language
2) What are the basic rules to remember for Coffee Script?
The basic rule for
Coffee Script
·
Whitespace matters: There are no curly
braces in CoffeeScript
·
No parentheses: Functions that take
arguments do not require parentheses
3) What is transpilers?
CoffeeScript code has
to be translated into JavaScript and to convert this code a tool is required.
This tool is known as transpilers.
4) What are the benefits of Coffee Script over JavaScript?
·
CoffeeScript allows you to express your
program with a lot less code than JavaScript
·
It has a lot of lightweight add-ons like
Ruby string Interpolation and Python style list comprehension
·
Makes everyday tasks easier to perform
with CoffeScript rather than JavaScript
5) How variables differ in CoffeeScript than JavaScript?
For variables in
JavaScript, you have to add semi-colon at the end of it to execute while in
CoffeeScript there is no need to add Semi-colon at the end of the statement.
Unlike, JavaScript, CoffeeScript adds up semi-colon with ease.
6) Explain functions in CoffeeScript?
Functions in
CoffeeScript is an (Optional) list of parameters followed by an arrow and then
the function body.
For example, log =
(message) à console.log message
7) How CoffeeScript compiler is helpful in CoffeeScript?
CoffeeScript compiler ensures that
within the lexical scope, all your variables are properly declared, and you
never need to write “var” yourself
8) What are the two different kinds of loops does CoffeeScript
provide?
Like JavaScript,
CoffeeScript also provides two different kind of loops
·
One for iterating over an array
·
One for iterating over the properties of
an object
9) Explain what is Splat in CoffeeScript?
Splat is the term used
for ( . . . ) operator for var-argument. Splatted arguments can come either
before, after or between standard arguments.
For example, (first, rest . . . )
10) Explain how you can define a range array in CoffeeScript?
In two ways, you can
define a range array in CoffeeScript
·
Inclusive range: This range is always
defined by (. . ) operator
·
Exclusive range: This range is always
defined by (. . . ) and it always omit the last value
For example, myArray =
[ 1..10 ] & myArray = [ 1. . . 10 ]
11) Explain what is the use of CoffeeScript’s chained comparison
syntax?
CoffeeScript’s chained
comparison syntax is used to know whether any given variable falls inside a
given range and also it enables to chain the two comparisons together in a form
that matches closely.
12) Explain about class methods in CoffeeScript?
CoffeeScript store
class object on the object itself rather than on the object prototype, which
saves memory and gives a central location to store class-level values
13) Explain how you could do Callback binding in CoffeeScript?
In order to bind a
callback function to an object you can use the fat arrow (=>) instead of the
normal arrow (à) , the function gets automatically bound to the object.
For example, $ ( ‘.product’ ). Click (
event ) =>
14) In CoffeeScript how clone-function is useful ?
Clone function is
useful in creating a complete new object in Coffee Script by
·
Copying all attributes from the source
object to the new object
·
Repeating the steps of copying
attributes from the source object for all sub-objects by calling the
clone-function
·
Creating a new object as the source
object
15) Explain what is the difference between copying an object
through assignment and clone-function ?
The difference between
copying an object through assignment and clone function is that how they handle
references. The assignment only copies the object’s references while
clone-function creates a complete new object.
16) Explain how you can replace a portion of a string with another
value?
To match and replace a
portion of a string with another value, Regular Expression can be used.
17) Explain how CoffeeScript interpolates the strings?
CoffeeScript
interpolates the strings in the same fashion as ruby; most expressions are
valid inside the # {. .. } interpolation syntax
18) How does Boolean work with CoffeeScript?
Booleans in
CoffeeScript is same as other but instead of “True” or “False” it is more
likely represented as “on” or “Yes” instead of true while “off” or “No” instead
of false.
19) Explain how you can detect and create missing function in
CoffeeScript?
To detect and create
missing function in CoffeeScript, you can use the existential assignment
operator (?=)
20) Can you bind parameters to properties in CoffeeScript?
Yes, CoffeeScript
allows to bind parameters to properties by using the @ shorthand, this also
allows you to define class functions.
21) In CoffeeScript how you can search a substring and how you can
return either the starting position of the match or the matching value itself?
There are several methods for doing this
using regular expressions. Some methods are called on a RegExppattern or object
while some are called on String objects.
·
RegExp objects: One way is to call the
test method on a RegExp pattern or object. The test method returns a boolean
value
·
String objects: The match method matches
the given string with the RegExp.
22) Explain how you can call a function from within that same
function in CoffeeScript?
To call a function from within that same
function, you can use @arguments.callee for unnamed function
while named functions keep their purpose explicit and make more of a code. The arguments.callee allows for the
recursion of an anonymous function.
23) How can you map an array in CoffeeScript?
Coffee script has clean support for
anonymous functions, to map an array in object usemap() with an anonymous
function. For simple mapping, list comprehension is more useful as Coffee
script directly support list comprehensions.
24) Explain how you can use arrays to Swap variables?
To swap variables
using array, you can use CoffeeScript’s destructuring assignment syntax, it
allows swapping two values without the use of a temporary variable.
25) What is the use of Existential Operators in CoffeeScript?
Existential Operators
in CoffeeScript can be used for
·
To check the existence of a variable
·
For conditional assignment
·
For function chaining
No comments:
Post a Comment