Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7428983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:53:50+00:00 2026-05-29T08:53:50+00:00

Today, while I was randomly reading the JavaScript patterns O’Reilly book, I found one

  • 0

Today, while I was randomly reading the JavaScript patterns O’Reilly book, I found one interesting thing (page 27 for reference).

In Javascript, in some cases, there is a difference if the brace start location is different.

function test_function1() {
    return
    {
        name: 'rajat'
    };
}

var obj = test_function1();
alert(obj);  //Shows "undefined"

While

function test_function2() {
    return {
        name: 'rajat'
    };
}

var obj = test_function2();
alert(obj); //Shows object

JSfiddle Demo

Does any other language out there have such behavior? If so, then I would have to change my habit for sure..:)

I am mainly concerned about PHP, C, C++, Java, and ruby.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:53:51+00:00Added an answer on May 29, 2026 at 8:53 am

    Any language that doesn’t rely on semicolons (but instead on newlines) to delimit statements potentially allows this. Consider Python:

    >>> def foo():
    ...   return
    ...   { 1: 2 }
    ... 
    >>> def bar():
    ...   return { 1: 2 }
    ... 
    >>> foo()
    >>> bar()
    {1: 2}
    

    You might be able to construct a similar case in Visual Basic but off the top of my head I can’t figure out how because VB is pretty restrictive in where values may be placed. But the following should work, unless the static analyser complains about unreachable code:

    Try
        Throw New Exception()
    Catch ex As Exception
        Throw ex.GetBaseException()
    End Try
    
    ' versus
    
    Try
        Throw New Exception()
    Catch ex As Exception
        Throw
        ex.GetBaseException()
    End Try
    

    From the languages you mentioned, Ruby has the same property. PHP, C, C++ and Java do not simply because they discard newline as whitespace, and require semicolons to delimit statements.

    Here’s the equivalent code from the Python example in Ruby:

    >> def foo
    >>   return { 1 => 2 }
    >> end
    => nil
    >> def bar
    >>   return
    >>   { 1 => 2 }
    >> end
    => nil
    >> foo
    => {1=>2}
    >> bar
    => nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

While searching a bug in my code today I found a strange thing. When
While reading proggit today, I came upon this comment in a post about how
I found this today while looking at a library for an API . def
Today while inside a client's production system, I found a SQL Server query that
Right... this one had me baffled for a while today so maybe one of
I ran into an interesting problem while debugging SWIG typemaps today. Anyone care to
I started reading Programming Pearls today and while doing it's exercise I came across
I ran into an interesting SQL problem today and while I came up with
the last thing I want to minimize today is code that contains while and
I got an error today while trying to do some formatting to existing code.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.